diff options
author | Pierre Pfister <ppfister@cisco.com> | 2017-07-27 22:57:34 -0400 |
---|---|---|
committer | Pierre Pfister <ppfister@cisco.com> | 2017-09-05 18:10:40 +0200 |
commit | 9a244bb5e4a21835cac51ba7f35095b9c24547e6 (patch) | |
tree | ad8874c4ee37e1cebc85592982547ad4dd5858fc /src/vlib/unix/util.c | |
parent | 215961829c4ae5f738ffcd01a8d1afcab13bd0e2 (diff) |
Add pidfile cmdline option
Change-Id: Ibaa61b624eb6683b1be6901a7b29f5f73aad27b2
Signed-off-by: Pierre Pfister <ppfister@cisco.com>
Diffstat (limited to 'src/vlib/unix/util.c')
-rw-r--r-- | src/vlib/unix/util.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/vlib/unix/util.c b/src/vlib/unix/util.c index 93aeb99c5d9..312cc9b5a0a 100644 --- a/src/vlib/unix/util.c +++ b/src/vlib/unix/util.c @@ -257,6 +257,55 @@ done: return error; } +clib_error_t * +vlib_unix_validate_runtime_file (unix_main_t * um, + const char *path, u8 ** full_path) +{ + u8 *fp = 0; + char *last_slash = 0; + + if (path[0] == '\0') + { + return clib_error_return (0, "path is an empty string"); + } + else if (strncmp (path, "../", 3) == 0 || strstr (path, "/../")) + { + return clib_error_return (0, "'..' not allowed in runtime path"); + } + else if (path[0] == '/') + { + /* Absolute path. Has to start with runtime directory */ + if (strncmp ((char *) um->runtime_dir, path, + strlen ((char *) um->runtime_dir))) + { + return clib_error_return (0, + "file %s is not in runtime directory %s", + path, um->runtime_dir); + } + fp = format (0, "%s%c", path, '\0'); + } + else + { + /* Relative path, just append to runtime */ + fp = format (0, "%s/%s%c", um->runtime_dir, path, '\0'); + } + + /* We don't want to create a directory out of the last file */ + if ((last_slash = strrchr ((char *) fp, '/')) != NULL) + *last_slash = '\0'; + + clib_error_t *error = vlib_unix_recursive_mkdir ((char *) fp); + + if (last_slash != NULL) + *last_slash = '/'; + + if (error) + vec_free (fp); + + *full_path = fp; + return error; +} + /* * fd.io coding-style-patch-verification: ON * |