aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2023-02-10 13:41:50 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2023-02-10 13:41:50 -0500
commitddc018b7860211b250ecd5ca80912497e09f1d36 (patch)
treea3c2d92a46636f88bb560fcf34b5184359bf33e1
parent85e5ffb65afea07b10dd4fad9aa4c48268864812 (diff)
downloadmstat-ddc018b7860211b250ecd5ca80912497e09f1d36.tar.gz
Move filename modification below PID assignment
-rw-r--r--mstat.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/mstat.c b/mstat.c
index 867a335..14f0651 100644
--- a/mstat.c
+++ b/mstat.c
@@ -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) {