diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-02-10 13:41:50 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-02-10 13:41:50 -0500 |
commit | ddc018b7860211b250ecd5ca80912497e09f1d36 (patch) | |
tree | a3c2d92a46636f88bb560fcf34b5184359bf33e1 /mstat.c | |
parent | 85e5ffb65afea07b10dd4fad9aa4c48268864812 (diff) | |
download | mstat-ddc018b7860211b250ecd5ca80912497e09f1d36.tar.gz |
Move filename modification below PID assignment
Diffstat (limited to 'mstat.c')
-rw-r--r-- | mstat.c | 40 |
1 files changed, 20 insertions, 20 deletions
@@ -173,26 +173,6 @@ int main(int argc, char *argv[]) { signal(SIGINT, handle_interrupt); signal(SIGTERM, handle_interrupt); - // Set up output directory root and file path - snprintf(option.filename, PATH_MAX - 1, "%d.mstat", option.pid); - if (strlen(option.root)) { - // Strip trailing slash from path - if (strlen(option.root) > 1 && strrchr(option.root, '/')) { - option.root[strlen(option.root) - 1] = '\0'; - } - - // Die if the output directory doesn't exist - if (access(option.root, X_OK) < 0) { - perror(option.root); - exit(1); - } - - // Construct new filename - char tmppath[PATH_MAX]; - snprintf(tmppath, PATH_MAX - 1, "%s/%s", option.root, option.filename); - strncpy(option.filename, tmppath, PATH_MAX - 1); - } - // Figure out what we are going to monitor. // Will it be a user-defined PID or a new process? if (option.pid) { @@ -237,6 +217,26 @@ int main(int argc, char *argv[]) { exit(1); } + // Set up output directory root and file path + snprintf(option.filename, PATH_MAX - 1, "%d.mstat", option.pid); + if (strlen(option.root)) { + // Strip trailing slash from path + if (strlen(option.root) > 1 && strrchr(option.root, '/')) { + option.root[strlen(option.root) - 1] = '\0'; + } + + // Die if the output directory doesn't exist + if (access(option.root, X_OK) < 0) { + perror(option.root); + exit(1); + } + + // Construct new filename + char tmppath[PATH_MAX]; + snprintf(tmppath, PATH_MAX - 1, "%s/%s", option.root, option.filename); + strncpy(option.filename, tmppath, PATH_MAX - 1); + } + // Remove previous mstat data file if clobber is enabled if (access(option.filename, F_OK) == 0) { if (option.clobber) { |