aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2024-10-04 08:40:39 -0400
committerGitHub <noreply@github.com>2024-10-04 08:40:39 -0400
commitd7e3deba72703ad36c497f5becf6772ca00a0d6d (patch)
treeeff3b2ec3dcc31126041529c8e00a714997f2d7b /src/utils.c
parent9691ccf51b3efd8113e9620c4afa8b5382d7f161 (diff)
parentf0ba8cd378a460f927644e41f49be95d0e956f81 (diff)
downloadstasis-d7e3deba72703ad36c497f5becf6772ca00a0d6d.tar.gz
Merge pull request #46 from jhunkeler/split-delivery-code
Add multiprocessing / Split delivery code
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/utils.c b/src/utils.c
index c0b3733..e037088 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -34,7 +34,7 @@ int popd() {
int rmtree(char *_path) {
int status = 0;
char path[PATH_MAX] = {0};
- strncpy(path, _path, sizeof(path));
+ strncpy(path, _path, sizeof(path) - 1);
DIR *dir;
struct dirent *d_entity;
@@ -122,10 +122,10 @@ char *expandpath(const char *_path) {
}
// Construct the new path
- strncat(result, home, PATH_MAX - 1);
+ strncat(result, home, sizeof(result) - strlen(home) + 1);
if (sep) {
- strncat(result, DIR_SEP, PATH_MAX - 1);
- strncat(result, ptmp, PATH_MAX - 1);
+ strncat(result, DIR_SEP, sizeof(result) - strlen(home) + 1);
+ strncat(result, ptmp, sizeof(result) - strlen(home) + 1);
}
return strdup(result);
@@ -315,7 +315,7 @@ int git_clone(struct Process *proc, char *url, char *destdir, char *gitref) {
}
static char command[PATH_MAX];
- sprintf(command, "%s clone --recursive %s", program, url);
+ sprintf(command, "%s clone -c advice.detachedHead=false --recursive %s", program, url);
if (destdir && access(destdir, F_OK) < 0) {
sprintf(command + strlen(command), " %s", destdir);
result = shell(proc, command);
@@ -444,7 +444,10 @@ void msg(unsigned type, char *fmt, ...) {
void debug_shell() {
msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "ENTERING STASIS DEBUG SHELL\n" STASIS_COLOR_RESET);
- system("/bin/bash -c 'PS1=\"(STASIS DEBUG) \\W $ \" bash --norc --noprofile'");
+ if (system("/bin/bash -c 'PS1=\"(STASIS DEBUG) \\W $ \" bash --norc --noprofile'") < 0) {
+ SYSERROR("unable to spawn debug shell: %s", strerror(errno));
+ exit(errno);
+ }
msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "EXITING STASIS DEBUG SHELL\n" STASIS_COLOR_RESET);
exit(255);
}
@@ -465,12 +468,23 @@ char *xmkstemp(FILE **fp, const char *mode) {
fd = mkstemp(t_name);
*fp = fdopen(fd, mode);
if (!*fp) {
+ // unable to open, die
if (fd > 0)
close(fd);
*fp = NULL;
return NULL;
}
+
char *path = strdup(t_name);
+ if (!path) {
+ // strdup failed, die
+ if (*fp) {
+ // close the file handle
+ fclose(*fp);
+ *fp = NULL;
+ }
+ // fall through. path is NULL.
+ }
return path;
}