Return value and code style improvements to swayrun

This commit is contained in:
Corey Hinshaw 2019-02-12 08:49:40 -05:00
parent 9b10a16775
commit 4f48f13397
2 changed files with 8 additions and 8 deletions

View file

@ -107,7 +107,7 @@ if scdoc.found()
'sway/sway-output.5.scd', 'sway/sway-output.5.scd',
'swaymsg/swaymsg.1.scd', 'swaymsg/swaymsg.1.scd',
'swaynag/swaynag.1.scd', 'swaynag/swaynag.1.scd',
'swaynag/swaynag.5.scd' 'swaynag/swaynag.5.scd',
] ]
foreach filename : man_files foreach filename : man_files
topic = filename.split('.')[-3].split('/')[-1] topic = filename.split('.')[-3].split('/')[-1]

View file

@ -10,9 +10,9 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
char *shell = getenv("SHELL"); char *shell = getenv("SHELL");
if (shell) { if (shell && strlen(shell)) {
// 3 exec arguments + argc + argv[argc] NULL pointer // 3 exec arguments + argc + argv[argc] NULL pointer
int exec_argc = 4 + argc; size_t exec_argc = 4 + argc;
char **exec_argv = malloc(exec_argc * sizeof(char *)); char **exec_argv = malloc(exec_argc * sizeof(char *));
// Prefix - to shell path to indicate login shell // Prefix - to shell path to indicate login shell
@ -20,7 +20,7 @@ int main(int argc, char **argv) {
strcpy(login_shell, "-"); strcpy(login_shell, "-");
strcat(login_shell, shell); strcat(login_shell, shell);
// Build the argumrnts to exec // Build the arguments to exec
memcpy(exec_argv + 3, argv, (argc + 1) * sizeof(argv)); memcpy(exec_argv + 3, argv, (argc + 1) * sizeof(argv));
exec_argv[0] = login_shell; exec_argv[0] = login_shell;
exec_argv[1] = "-c"; exec_argv[1] = "-c";
@ -28,12 +28,12 @@ int main(int argc, char **argv) {
exec_argv[3] = shell; exec_argv[3] = shell;
execvp(shell, exec_argv); execvp(shell, exec_argv);
fprintf(stderr, "Could not run %s using login shell: %s\n", SWAY_COMMAND, shell); fprintf(stderr, "Could not run %s using login shell %s: %s\n", SWAY_COMMAND, shell, strerror(errno));
} else { } else {
argv[0] = SWAY_COMMAND; argv[0] = SWAY_COMMAND;
execvp(SWAY_COMMAND, argv); execvp(SWAY_COMMAND, argv);
fprintf(stderr, "Could not run %s\n", SWAY_COMMAND); fprintf(stderr, "Could not run %s: %s\n", SWAY_COMMAND, strerror(errno));
} }
return errno; return EXIT_FAILURE;
} }