diff --git a/ipc.h b/ipc.h index 9e9f994..d9d8248 100644 --- a/ipc.h +++ b/ipc.h @@ -40,4 +40,4 @@ typedef struct ipc { } ipc_t; -#define SERVER_PATH "/tmp/rogue-enemy.sock" \ No newline at end of file +#define SERVER_PATH "/home/rogue-enemy.sock" \ No newline at end of file diff --git a/notes/launch.json b/notes/launch.json new file mode 100644 index 0000000..6374a97 --- /dev/null +++ b/notes/launch.json @@ -0,0 +1,31 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/allynone", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "miDebuggerPath": "/home/gamer/gdb", + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + + + + ] +} \ No newline at end of file diff --git a/notes/vscode_debug.md b/notes/vscode_debug.md new file mode 100644 index 0000000..50e53d4 --- /dev/null +++ b/notes/vscode_debug.md @@ -0,0 +1,13 @@ +# Debug sudo application with vscode + + 1. create /home/gamer/gdb with following content: +``` +sudo /usr/bin/gdb "$@" +``` + + 2. add this line to /etc/sudoers +``` +gamer ALL=(ALL) NOPASSWD:/usr/bin/gdb +``` + +then copy the launch.json in this folder into .vscode folder \ No newline at end of file diff --git a/stray_ally.c b/stray_ally.c index 51ba18e..5322cbb 100644 --- a/stray_ally.c +++ b/stray_ally.c @@ -110,15 +110,16 @@ int main(int argc, char ** argv) { // here the client_fd is good if (pthread_mutex_lock(&dev_out_thread_data.communication.endpoint.ssocket.mutex) == 0) { - int i; - for (i = 0; i < MAX_CONNECTED_CLIENTS; ++i) { + bool found = false; + for (size_t i = 0; i < MAX_CONNECTED_CLIENTS; ++i) { if (dev_out_thread_data.communication.endpoint.ssocket.clients[i] < 0) { dev_out_thread_data.communication.endpoint.ssocket.clients[i] = client_fd; + found = true; break; } } - if (i == MAX_CONNECTED_CLIENTS) { + if (!found) { fprintf(stderr, "Could not find a free spot fot the incoming client -- client will be rejected\n"); close(client_fd); }