-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: allow setting stdout/err for exec
Introduces the exec_output command, which sets the file to use for stdout and stderr in the exec and exec_always commands.
- Loading branch information
1 parent
801bc76
commit 9805c84
Showing
7 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include "sway/commands.h" | ||
|
||
struct cmd_results *cmd_exec_output(int argc, char **argv) { | ||
struct cmd_results *error = | ||
checkarg(argc, "exec_output", EXPECTED_AT_MOST, 1); | ||
if (error) { | ||
return error; | ||
} | ||
|
||
if (config->exec_out >= 0) { | ||
if (close(config->exec_out) < 0) { | ||
return cmd_results_new( | ||
CMD_FAILURE, | ||
"Failed to close existing fd %d", | ||
config->exec_out | ||
); | ||
}; | ||
config->exec_out = -1; | ||
} | ||
|
||
if (argc == 0) { | ||
return cmd_results_new(CMD_SUCCESS, NULL); | ||
} | ||
|
||
int out = open(argv[0], O_RDWR | O_APPEND | O_CREAT, 0600); // u=rw | ||
if (out < 0) { | ||
return cmd_results_new(CMD_FAILURE, "Could not open file %s", argv[0]); | ||
} | ||
config->exec_out = out; | ||
return cmd_results_new(CMD_SUCCESS, NULL); | ||
} | ||
|
||
#undef OPEN_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters