diff options
author | Jim Keniston <jkenisto@us.ibm.com> | 2009-04-15 16:02:58 -0700 |
---|---|---|
committer | Jim Keniston <jkenisto@us.ibm.com> | 2009-04-15 16:02:58 -0700 |
commit | 900686f5e209099d493a15f4e36a5030dc0aa8be (patch) | |
tree | 405757c92915c516cd0ff28e217a000843573f3f /runtime/staprun | |
parent | 2020af07c2a7f58538874ce652b52a6883f7ada0 (diff) | |
parent | 7c2136cfc88d68cfc5eb490444dc25c7dc1c0632 (diff) | |
download | systemtap-steved-900686f5e209099d493a15f4e36a5030dc0aa8be.tar.gz systemtap-steved-900686f5e209099d493a15f4e36a5030dc0aa8be.tar.xz systemtap-steved-900686f5e209099d493a15f4e36a5030dc0aa8be.zip |
Merge branch 'master' of ssh://kenistoj@sources.redhat.com/git/systemtap
Diffstat (limited to 'runtime/staprun')
-rw-r--r-- | runtime/staprun/common.c | 9 | ||||
-rw-r--r-- | runtime/staprun/relay.c | 19 | ||||
-rw-r--r-- | runtime/staprun/relay_old.c | 22 | ||||
-rw-r--r-- | runtime/staprun/staprun_funcs.c | 15 |
4 files changed, 48 insertions, 17 deletions
diff --git a/runtime/staprun/common.c b/runtime/staprun/common.c index 8200ec9d..26b166c2 100644 --- a/runtime/staprun/common.c +++ b/runtime/staprun/common.c @@ -82,7 +82,7 @@ int stap_strfloctime(char *buf, size_t max, const char *fmt, time_t t) num = tm.tm_year % 100; goto numbering02; case 'C': - num = ((tm.tm_year + 1900 - 1) / 100) + 1; + num = ((tm.tm_year + 1900) / 100); goto numbering; case 'm': num = tm.tm_mon + 1; @@ -107,7 +107,7 @@ int stap_strfloctime(char *buf, size_t max, const char *fmt, time_t t) if (num == 0) num = 12; goto numbering02; case 'j': - ret = snprintf(c, end - c, "%03d", tm.tm_yday); + ret = snprintf(c, end - c, "%03d", tm.tm_yday + 1); if (ret < 0) return ret; c += ret; break; @@ -117,7 +117,10 @@ int stap_strfloctime(char *buf, size_t max, const char *fmt, time_t t) case 'l': num = tm.tm_hour % 12; if (num == 0) num = 12; - goto numbering; + ret = snprintf(c, end - c, "%2d", num); + if (ret < 0) return ret; + c += ret; + break; case 'M': num = tm.tm_min; goto numbering02; diff --git a/runtime/staprun/relay.c b/runtime/staprun/relay.c index 50f295b5..b9796241 100644 --- a/runtime/staprun/relay.c +++ b/runtime/staprun/relay.c @@ -185,7 +185,7 @@ static void *reader_thread(void *data) dbug(3, "cpu=%d poll=%d errno=%d\n", cpu, rc, errno); if (errno != EINTR) { _perr("poll error"); - return(NULL); + goto error_out; } } while ((rc = read(relay_fd[cpu], buf, sizeof(buf))) > 0) { @@ -198,17 +198,24 @@ static void *reader_thread(void *data) remove_file = 1; if (open_outfile(fnum, cpu, remove_file) < 0) { perr("Couldn't open file for cpu %d, exiting.", cpu); - return(NULL); + goto error_out; } - wsize = 0; + wsize = rc; } if (write(out_fd[cpu], buf, rc) != rc) { - perr("Couldn't write to output %d for cpu %d, exiting.", out_fd[cpu], cpu); - return(NULL); + if (errno != EPIPE) + perr("Couldn't write to output %d for cpu %d, exiting.", out_fd[cpu], cpu); + goto error_out; } } } while (!stop_threads); - dbug(3, "exiting thread %d\n", cpu); + dbug(3, "exiting thread for cpu %d\n", cpu); + return(NULL); + +error_out: + /* Signal the main thread that we need to quit */ + kill(getpid(), SIGTERM); + dbug(2, "exiting thread for cpu %d after error\n", cpu); return(NULL); } diff --git a/runtime/staprun/relay_old.c b/runtime/staprun/relay_old.c index ef8fd0da..33d2daf3 100644 --- a/runtime/staprun/relay_old.c +++ b/runtime/staprun/relay_old.c @@ -239,14 +239,15 @@ static int process_subbufs(struct _stp_buf_info *info, scb->rmfile = 1; if (open_oldoutfile(scb->fnum, cpu, scb->rmfile) < 0) { perr("Couldn't open file for cpu %d, exiting.", cpu); - exit(1); + return -1; } - scb->wsize = 0; + scb->wsize = len; } if (len) { if (fwrite_unlocked (subbuf_ptr, len, 1, percpu_tmpfile[cpu]) != 1) { - _perr("Couldn't write to output file for cpu %d, exiting:", cpu); - exit(1); + if (errno != EPIPE) + _perr("Couldn't write to output file for cpu %d, exiting:", cpu); + return -1; } } subbufs_consumed++; @@ -281,14 +282,17 @@ static void *reader_thread(void *data) if (rc < 0) { if (errno != EINTR) { _perr("poll error"); - exit(1); + break; } err("WARNING: poll warning: %s\n", strerror(errno)); rc = 0; } rc = read(proc_fd[cpu], &status[cpu].info, sizeof(struct _stp_buf_info)); - subbufs_consumed = process_subbufs(&status[cpu].info, &scb); + rc = process_subbufs(&status[cpu].info, &scb); + if (rc < 0) + break; + subbufs_consumed = rc; if (subbufs_consumed) { if (subbufs_consumed > status[cpu].max_backlog) status[cpu].max_backlog = subbufs_consumed; @@ -301,6 +305,10 @@ static void *reader_thread(void *data) if (status[cpu].info.flushing) pthread_exit(NULL); } while (1); + + /* Signal the main thread that we need to quit */ + kill(getpid(), SIGTERM); + pthread_exit(NULL); } /** @@ -320,7 +328,7 @@ int write_realtime_data(void *data, ssize_t nb) perr("Couldn't open file, exiting."); return -1; } - global_scb.wsize = 0; + global_scb.wsize = nb; } bw = write(out_fd[0], data, nb); if (bw >= 0 && bw != nb) { diff --git a/runtime/staprun/staprun_funcs.c b/runtime/staprun/staprun_funcs.c index e94e5d13..49b37988 100644 --- a/runtime/staprun/staprun_funcs.c +++ b/runtime/staprun/staprun_funcs.c @@ -316,8 +316,21 @@ int check_permissions(void) int path_check = 0; /* If we're root, we can do anything. */ - if (getuid() == 0) + if (getuid() == 0) { + /* ... like overriding the real UID */ + const char *env_id = getenv("SYSTEMTAP_REAL_UID"); + if (env_id && setreuid(atoi(env_id), -1)) + err("WARNING: couldn't set staprun UID to '%s': %s", + env_id, strerror(errno)); + + /* ... or overriding the real GID */ + env_id = getenv("SYSTEMTAP_REAL_GID"); + if (env_id && setregid(atoi(env_id), -1)) + err("WARNING: couldn't set staprun GID to '%s': %s", + env_id, strerror(errno)); + return 1; + } /* Lookup the gid for group "stapdev" */ errno = 0; |