本文整理汇总了C++中safe_write函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_write函数的具体用法?C++ safe_write怎么用?C++ safe_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_write函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: entermsg
//.........这里部分代码省略.........
snprintf(hoobab, sizeof hoobab, "%s/messages/base%3.3d/fa%5.5d", conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, header.MSG_NUMBER);
mkdir(hoobab, 0777);
setperm(hoobab, 0777);
while (fgetsnolf(hoobab, 1024, fd)) {
char sr[1024];
char de[1024];
snprintf(sr, sizeof sr, "%s/%s", currnode->MULTI_TEMPORARY, hoobab);
snprintf(de, sizeof de, "%s/messages/base%3.3d/fa%5.5d/%s", conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, header.MSG_NUMBER, hoobab);
newrename(sr, de);
}
fclose(fd);
snprintf(hoobab, sizeof hoobab, "%s/messages/base%3.3d/msf%5.5d", conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, header.MSG_NUMBER);
newrename(fabuf, hoobab);
} else {
*header.MSG_ATTACH = 0;
}
}
if (toupper(current_msgbase->MSGBASE_FN_FLAGS) != 'L') {
header.MSG_FN_ORIG_ZONE = current_msgbase->MSGBASE_FN_ZONE;
header.MSG_FN_ORIG_NET = current_msgbase->MSGBASE_FN_NET;
header.MSG_FN_ORIG_NODE = current_msgbase->MSGBASE_FN_NODE;
header.MSG_FN_ORIG_POINT = current_msgbase->MSGBASE_FN_POINT;
header.MSG_FLAGS |= (1L << 2);
}
if ((msgfd = ddmsg_open_base(conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, O_RDWR | O_CREAT, 0666)) == -1) {
DDPut(sd[emwriteerrstr]);
free(lineedmem);
return 0;
}
fsetperm(msgfd, 0666);
lseek(msgfd, 0, SEEK_END);
safe_write(msgfd, &header, sizeof(struct DayDream_Message));
ddmsg_close_base(msgfd);
if ((msgfd = ddmsg_open_msg(conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, header.MSG_NUMBER, O_RDWR | O_CREAT | O_TRUNC, 0666)) == -1) {
DDPut(sd[emwriteerrstr]);
free(lineedmem);
return 0;
}
fsetperm(msgfd, 0666);
if (toupper(current_msgbase->MSGBASE_FN_FLAGS) == 'E') {
char ub[128];
int uq;
strlcpy(ub, current_msgbase->MSGBASE_FN_TAG, sizeof ub);
strupr(ub);
snprintf(ebuf, sizeof ebuf, "AREA:%s\n", ub);
safe_write(msgfd, ebuf, strlen(ebuf));
if ((uq = getfidounique())) {
snprintf(ebuf, sizeof ebuf, "\001MSGID: %d:%d/%d.%d %8.8x\n", current_msgbase->MSGBASE_FN_ZONE, current_msgbase->MSGBASE_FN_NET, current_msgbase->MSGBASE_FN_NODE, current_msgbase->MSGBASE_FN_POINT, uq);
safe_write(msgfd, ebuf, strlen(ebuf));
if (header.MSG_ORIGINAL) {
if (getreplyid(header.MSG_ORIGINAL, ebuf, sizeof ebuf))
safe_write(msgfd, ebuf, strlen(ebuf));
}
}
} else if (toupper(current_msgbase->MSGBASE_FN_FLAGS) == 'N') {
snprintf(ebuf, sizeof ebuf, "\001INTL %d:%d/%d %d:%d/%d\n",
header.MSG_FN_DEST_ZONE, header.MSG_FN_DEST_NET,
header.MSG_FN_DEST_NODE, header.MSG_FN_ORIG_ZONE,
header.MSG_FN_ORIG_NET, header.MSG_FN_ORIG_NODE);
safe_write(msgfd, ebuf, strlen(ebuf));
if (header.MSG_FN_DEST_POINT) {
开发者ID:ryanfantus,项目名称:daydream,代码行数:67,代码来源:entermsg.c
示例2: _handle_signal_task_local
static int
_handle_signal_task_local(int fd, stepd_step_rec_t *job, uid_t uid)
{
int rc = SLURM_SUCCESS;
int signal;
int ltaskid; /* local task index */
safe_read(fd, &signal, sizeof(int));
safe_read(fd, <askid, sizeof(int));
debug("_handle_signal_task_local for step=%u.%u uid=%d signal=%d",
job->jobid, job->stepid, (int) uid, signal);
if (uid != job->uid && !_slurm_authorized_user(uid)) {
debug("kill req from uid %ld for job %u.%u owned by uid %ld",
(long)uid, job->jobid, job->stepid, (long)job->uid);
rc = EPERM;
goto done;
}
/*
* Sanity checks
*/
if (ltaskid < 0 || ltaskid >= job->node_tasks) {
debug("step %u.%u invalid local task id %d",
job->jobid, job->stepid, ltaskid);
rc = SLURM_ERROR;
goto done;
}
if (!job->task
|| !job->task[ltaskid]) {
debug("step %u.%u no task info for task id %d",
job->jobid, job->stepid, ltaskid);
rc = SLURM_ERROR;
goto done;
}
if (job->task[ltaskid]->pid <= 1) {
debug("step %u.%u invalid pid %d for task %d",
job->jobid, job->stepid,
job->task[ltaskid]->pid, ltaskid);
rc = SLURM_ERROR;
goto done;
}
/*
* Signal the task
*/
slurm_mutex_lock(&suspend_mutex);
if (suspended) {
rc = ESLURMD_STEP_SUSPENDED;
slurm_mutex_unlock(&suspend_mutex);
goto done;
}
if (kill(job->task[ltaskid]->pid, signal) == -1) {
rc = -1;
verbose("Error sending signal %d to %u.%u, pid %d: %m",
signal, job->jobid, job->stepid,
job->task[ltaskid]->pid);
} else {
verbose("Sent signal %d to %u.%u, pid %d",
signal, job->jobid, job->stepid,
job->task[ltaskid]->pid);
}
slurm_mutex_unlock(&suspend_mutex);
done:
/* Send the return code */
safe_write(fd, &rc, sizeof(int));
return SLURM_SUCCESS;
rwfail:
return SLURM_FAILURE;
}
开发者ID:francois-wellenreiter,项目名称:slurm,代码行数:72,代码来源:req.c
示例3: _handle_checkpoint_tasks
static int
_handle_checkpoint_tasks(int fd, stepd_step_rec_t *job, uid_t uid)
{
int rc = SLURM_SUCCESS;
time_t timestamp;
int len;
char *image_dir = NULL;
debug3("_handle_checkpoint_tasks for job %u.%u",
job->jobid, job->stepid);
safe_read(fd, ×tamp, sizeof(time_t));
safe_read(fd, &len, sizeof(int));
if (len) {
image_dir = xmalloc (len);
safe_read(fd, image_dir, len); /* '\0' terminated */
}
debug3(" uid = %d", uid);
if (uid != job->uid && !_slurm_authorized_user(uid)) {
debug("checkpoint req from uid %ld for job %u.%u "
"owned by uid %ld",
(long)uid, job->jobid, job->stepid, (long)job->uid);
rc = EPERM;
goto done;
}
if (job->ckpt_timestamp &&
timestamp == job->ckpt_timestamp) {
debug("duplicate checkpoint req for job %u.%u, "
"timestamp %ld. discarded.",
job->jobid, job->stepid, (long)timestamp);
rc = ESLURM_ALREADY_DONE; /* EINPROGRESS? */
goto done;
}
/*
* Sanity checks
*/
if (job->pgid <= (pid_t)1) {
debug ("step %u.%u invalid [jmgr_pid:%d pgid:%u]",
job->jobid, job->stepid, job->jmgr_pid, job->pgid);
rc = ESLURMD_JOB_NOTRUNNING;
goto done;
}
slurm_mutex_lock(&suspend_mutex);
if (suspended) {
rc = ESLURMD_STEP_SUSPENDED;
slurm_mutex_unlock(&suspend_mutex);
goto done;
}
/* set timestamp in case another request comes */
job->ckpt_timestamp = timestamp;
/* TODO: do we need job->ckpt_dir any more,
* except for checkpoint/xlch? */
/* if (! image_dir) { */
/* image_dir = xstrdup(job->ckpt_dir); */
/* } */
/* call the plugin to send the request */
if (checkpoint_signal_tasks(job, image_dir) != SLURM_SUCCESS) {
rc = -1;
verbose("Error sending checkpoint request to %u.%u: %s",
job->jobid, job->stepid, slurm_strerror(rc));
} else {
verbose("Sent checkpoint request to %u.%u",
job->jobid, job->stepid);
}
slurm_mutex_unlock(&suspend_mutex);
done:
/* Send the return code */
safe_write(fd, &rc, sizeof(int));
xfree(image_dir);
return SLURM_SUCCESS;
rwfail:
return SLURM_FAILURE;
}
开发者ID:francois-wellenreiter,项目名称:slurm,代码行数:82,代码来源:req.c
示例4: _handle_suspend
static int
_handle_suspend(int fd, stepd_step_rec_t *job, uid_t uid)
{
static int launch_poe = -1;
int rc = SLURM_SUCCESS;
int errnum = 0;
uint16_t job_core_spec = (uint16_t) NO_VAL;
safe_read(fd, &job_core_spec, sizeof(uint16_t));
debug("_handle_suspend for step:%u.%u uid:%ld core_spec:%u",
job->jobid, job->stepid, (long)uid, job_core_spec);
if (!_slurm_authorized_user(uid)) {
debug("job step suspend request from uid %ld for job %u.%u ",
(long)uid, job->jobid, job->stepid);
rc = -1;
errnum = EPERM;
goto done;
}
_wait_for_job_init(job);
if (job->cont_id == 0) {
debug ("step %u.%u invalid container [cont_id:%"PRIu64"]",
job->jobid, job->stepid, job->cont_id);
rc = -1;
errnum = ESLURMD_JOB_NOTRUNNING;
goto done;
}
acct_gather_suspend_poll();
if (launch_poe == -1) {
char *launch_type = slurm_get_launch_type();
if (!xstrcmp(launch_type, "launch/poe"))
launch_poe = 1;
else
launch_poe = 0;
xfree(launch_type);
}
/*
* Signal the container
*/
slurm_mutex_lock(&suspend_mutex);
if (suspended) {
rc = -1;
errnum = ESLURMD_STEP_SUSPENDED;
slurm_mutex_unlock(&suspend_mutex);
goto done;
} else {
if (!job->batch && switch_g_job_step_pre_suspend(job))
error("switch_g_job_step_pre_suspend: %m");
/* SIGTSTP is sent first to let MPI daemons stop their tasks,
* then wait 2 seconds, then send SIGSTOP to the spawned
* process's container to stop everything else.
*
* In some cases, 1 second has proven insufficient. Longer
* delays may help insure that all MPI tasks have been stopped
* (that depends upon the MPI implementaiton used), but will
* also permit longer time periods when more than one job can
* be running on each resource (not good). */
if (launch_poe == 0) {
/* IBM MPI seens to periodically hang upon receipt
* of SIGTSTP. */
if (proctrack_g_signal(job->cont_id, SIGTSTP) < 0) {
verbose("Error suspending %u.%u (SIGTSTP): %m",
job->jobid, job->stepid);
} else
sleep(2);
}
if (proctrack_g_signal(job->cont_id, SIGSTOP) < 0) {
verbose("Error suspending %u.%u (SIGSTOP): %m",
job->jobid, job->stepid);
} else {
verbose("Suspended %u.%u", job->jobid, job->stepid);
}
suspended = true;
}
if (!job->batch && switch_g_job_step_post_suspend(job))
error("switch_g_job_step_post_suspend: %m");
if (!job->batch && core_spec_g_suspend(job->cont_id, job_core_spec))
error("core_spec_g_suspend: %m");
slurm_mutex_unlock(&suspend_mutex);
done:
/* Send the return code and errno */
safe_write(fd, &rc, sizeof(int));
safe_write(fd, &errnum, sizeof(int));
return SLURM_SUCCESS;
rwfail:
return SLURM_FAILURE;
}
开发者ID:francois-wellenreiter,项目名称:slurm,代码行数:96,代码来源:req.c
示例5: _handle_completion
static int
_handle_completion(int fd, stepd_step_rec_t *job, uid_t uid)
{
int rc = SLURM_SUCCESS;
int errnum = 0;
int first;
int last;
jobacctinfo_t *jobacct = NULL;
int step_rc;
char* buf;
int len;
Buf buffer;
bool lock_set = false;
debug("_handle_completion for job %u.%u",
job->jobid, job->stepid);
debug3(" uid = %d", uid);
if (!_slurm_authorized_user(uid)) {
debug("step completion message from uid %ld for job %u.%u ",
(long)uid, job->jobid, job->stepid);
rc = -1;
errnum = EPERM;
/* Send the return code and errno */
safe_write(fd, &rc, sizeof(int));
safe_write(fd, &errnum, sizeof(int));
return SLURM_SUCCESS;
}
safe_read(fd, &first, sizeof(int));
safe_read(fd, &last, sizeof(int));
safe_read(fd, &step_rc, sizeof(int));
/*
* We must not use getinfo over a pipe with slurmd here
* Indeed, slurmstepd does a large use of setinfo over a pipe
* with slurmd and doing the reverse can result in a deadlock
* scenario with slurmd :
* slurmd(lockforread,write)/slurmstepd(write,lockforread)
* Do pack/unpack instead to be sure of independances of
* slurmd and slurmstepd
*/
safe_read(fd, &len, sizeof(int));
buf = xmalloc(len);
safe_read(fd, buf, len);
buffer = create_buf(buf, len);
jobacctinfo_unpack(&jobacct, SLURM_PROTOCOL_VERSION,
PROTOCOL_TYPE_SLURM, buffer, 1);
free_buf(buffer);
/*
* Record the completed nodes
*/
slurm_mutex_lock(&step_complete.lock);
lock_set = true;
if (! step_complete.wait_children) {
rc = -1;
errnum = ETIMEDOUT; /* not used anyway */
goto timeout;
}
/* SlurmUser or root can craft a launch without a valid credential
* ("srun --no-alloc ...") and no tree information can be built
* without the hostlist from the credential. */
if (step_complete.rank >= 0) {
#if 0
char bits_string[128];
debug2("Setting range %d (bit %d) through %d(bit %d)",
first, first-(step_complete.rank+1),
last, last-(step_complete.rank+1));
bit_fmt(bits_string, sizeof(bits_string), step_complete.bits);
debug2(" before bits: %s", bits_string);
#endif
bit_nset(step_complete.bits,
first - (step_complete.rank+1),
last - (step_complete.rank+1));
#if 0
bit_fmt(bits_string, sizeof(bits_string), step_complete.bits);
debug2(" after bits: %s", bits_string);
#endif
}
step_complete.step_rc = MAX(step_complete.step_rc, step_rc);
/************* acct stuff ********************/
jobacctinfo_aggregate(step_complete.jobacct, jobacct);
timeout:
jobacctinfo_destroy(jobacct);
/*********************************************/
/* Send the return code and errno, we do this within the locked
* region to ensure that the stepd doesn't exit before we can
* perform this send. */
safe_write(fd, &rc, sizeof(int));
safe_write(fd, &errnum, sizeof(int));
slurm_cond_signal(&step_complete.cond);
slurm_mutex_unlock(&step_complete.lock);
return SLURM_SUCCESS;
//.........这里部分代码省略.........
开发者ID:francois-wellenreiter,项目名称:slurm,代码行数:101,代码来源:req.c
示例6: _handle_signal_container
//.........这里部分代码省略.........
debug3(" uid = %d", uid);
if (uid != job->uid && !_slurm_authorized_user(uid)) {
debug("kill container req from uid %ld for job %u.%u "
"owned by uid %ld",
(long)uid, job->jobid, job->stepid, (long)job->uid);
rc = -1;
errnum = EPERM;
goto done;
}
/*
* Sanity checks
*/
if (job->cont_id == 0) {
debug ("step %u.%u invalid container [cont_id:%"PRIu64"]",
job->jobid, job->stepid, job->cont_id);
rc = -1;
errnum = ESLURMD_JOB_NOTRUNNING;
goto done;
}
if ((job->nodeid == 0) && (msg_sent == 0) &&
(job->state < SLURMSTEPD_STEP_ENDING)) {
time_t now = time(NULL);
char entity[24], time_str[24];
if (job->stepid == SLURM_BATCH_SCRIPT) {
snprintf(entity, sizeof(entity), "JOB %u", job->jobid);
} else {
snprintf(entity, sizeof(entity), "STEP %u.%u",
job->jobid, job->stepid);
}
slurm_make_time_str(&now, time_str, sizeof(time_str));
/* Not really errors,
* but we want messages displayed by default */
if (sig == SIG_TIME_LIMIT) {
error("*** %s CANCELLED AT %s DUE TO TIME LIMIT ***",
entity, time_str);
msg_sent = 1;
} else if (sig == SIG_PREEMPTED) {
error("*** %s CANCELLED AT %s DUE TO PREEMPTION ***",
entity, time_str);
msg_sent = 1;
} else if (sig == SIG_NODE_FAIL) {
error("*** %s CANCELLED AT %s DUE TO NODE FAILURE ***",
entity, time_str);
msg_sent = 1;
} else if (sig == SIG_FAILURE) {
error("*** %s FAILED (non-zero exit code or other "
"failure mode) ***", entity);
msg_sent = 1;
} else if ((sig == SIGTERM) || (sig == SIGKILL)) {
error("*** %s CANCELLED AT %s ***", entity, time_str);
msg_sent = 1;
}
}
if ((sig == SIG_TIME_LIMIT) || (sig == SIG_NODE_FAIL) ||
(sig == SIG_PREEMPTED) || (sig == SIG_FAILURE))
goto done;
if (sig == SIG_DEBUG_WAKE) {
int i;
for (i = 0; i < job->node_tasks; i++)
pdebug_wake_process(job, job->task[i]->pid);
goto done;
}
if (sig == SIG_ABORT) {
sig = SIGKILL;
job->aborted = true;
}
pthread_mutex_lock(&suspend_mutex);
if (suspended && (sig != SIGKILL)) {
rc = -1;
errnum = ESLURMD_STEP_SUSPENDED;
pthread_mutex_unlock(&suspend_mutex);
goto done;
}
/*
* Signal the container
*/
if (slurm_container_signal(job->cont_id, sig) < 0) {
rc = -1;
errnum = errno;
verbose("Error sending signal %d to %u.%u: %m",
sig, job->jobid, job->stepid);
} else {
verbose("Sent signal %d to %u.%u",
sig, job->jobid, job->stepid);
}
pthread_mutex_unlock(&suspend_mutex);
done:
/* Send the return code and errnum */
safe_write(fd, &rc, sizeof(int));
safe_write(fd, &errnum, sizeof(int));
return SLURM_SUCCESS;
rwfail:
return SLURM_FAILURE;
}
开发者ID:lipari,项目名称:slurm,代码行数:101,代码来源:req.c
示例7: _handle_terminate
static int
_handle_terminate(int fd, stepd_step_rec_t *job, uid_t uid)
{
int rc = SLURM_SUCCESS;
int errnum = 0;
stepd_step_task_info_t *task;
uint32_t i;
debug("_handle_terminate for step=%u.%u uid=%d",
job->jobid, job->stepid, uid);
step_terminate_monitor_start(job->jobid, job->stepid);
if (uid != job->uid && !_slurm_authorized_user(uid)) {
debug("terminate req from uid %ld for job %u.%u "
"owned by uid %ld",
(long)uid, job->jobid, job->stepid, (long)job->uid);
rc = -1;
errnum = EPERM;
goto done;
}
/*
* Sanity checks
*/
if (job->cont_id == 0) {
debug ("step %u.%u invalid container [cont_id:%"PRIu64"]",
job->jobid, job->stepid, job->cont_id);
rc = -1;
errnum = ESLURMD_JOB_NOTRUNNING;
goto done;
}
/* cycle thru the tasks and mark those that have not
* called abort and/or terminated as killed_by_cmd
*/
for (i = 0; i < job->node_tasks; i++) {
if (NULL == (task = job->task[i])) {
continue;
}
if (task->aborted || task->exited) {
continue;
}
/* mark that this task is going to be killed by
* cmd so we ignore its exit status - otherwise,
* we will probably report the final exit status
* as SIGKILL
*/
task->killed_by_cmd = true;
}
/*
* Signal the container with SIGKILL
*/
slurm_mutex_lock(&suspend_mutex);
if (suspended) {
debug("Terminating suspended job step %u.%u",
job->jobid, job->stepid);
suspended = false;
}
if (proctrack_g_signal(job->cont_id, SIGKILL) < 0) {
if (errno != ESRCH) { /* No error if process already gone */
rc = -1;
errnum = errno;
}
verbose("Error sending SIGKILL signal to %u.%u: %m",
job->jobid, job->stepid);
} else {
verbose("Sent SIGKILL signal to %u.%u",
job->jobid, job->stepid);
}
slurm_mutex_unlock(&suspend_mutex);
done:
/* Send the return code and errnum */
safe_write(fd, &rc, sizeof(int));
safe_write(fd, &errnum, sizeof(int));
return SLURM_SUCCESS;
rwfail:
return SLURM_FAILURE;
}
开发者ID:francois-wellenreiter,项目名称:slurm,代码行数:81,代码来源:req.c
示例8: decompress_fd_xz
static int
decompress_fd_xz(int fdi, int fdo)
{
#ifdef HAVE_LZMA
uint8_t buf_in[BUFSIZ];
uint8_t buf_out[BUFSIZ];
lzma_stream strm = LZMA_STREAM_INIT;
lzma_ret ret = lzma_stream_decoder(&strm, UINT64_MAX, 0);
if (ret != LZMA_OK)
{
close(fdi);
close(fdo);
log_error("Failed to initialize XZ decoder: code %d", ret);
return -ENOMEM;
}
lzma_action action = LZMA_RUN;
strm.next_out = buf_out;
strm.avail_out = sizeof(buf_out);
for (;;)
{
if (strm.avail_in == 0 && action == LZMA_RUN)
{
strm.next_in = buf_in;
strm.avail_in = safe_read(fdi, buf_in, sizeof(buf_in));
if (strm.avail_in < 0)
{
perror_msg("Failed to read source core file");
close(fdi);
close(fdo);
lzma_end(&strm);
return -1;
}
if (strm.avail_in == 0)
action = LZMA_FINISH;
}
ret = lzma_code(&strm, action);
if (strm.avail_out == 0 || ret == LZMA_STREAM_END)
{
const ssize_t n = sizeof(buf_out) - strm.avail_out;
if (n != safe_write(fdo, buf_out, n))
{
perror_msg("Failed to write decompressed data");
close(fdi);
close(fdo);
lzma_end(&strm);
return -1;
}
if (ret == LZMA_STREAM_END)
{
log_debug("Successfully decompressed coredump.");
break;
}
strm.next_out = buf_out;
strm.avail_out = sizeof(buf_out);
}
}
return 0;
#else /*HAVE_LZMA*/
const char *cmd[] = { "xzcat", "-d", "-", NULL };
return decompress_using_fork_execvp(cmd, fdi, fdo);
#endif /*HAVE_LZMA*/
}
开发者ID:abrt,项目名称:libreport,代码行数:73,代码来源:compress.c
示例9: decompress_fd_lz4
static int
decompress_fd_lz4(int fdi, int fdo)
{
#ifdef HAVE_LZ4
enum { LZ4_DEC_BUF_SIZE = 64*1024u };
LZ4F_decompressionContext_t ctx = NULL;
LZ4F_errorCode_t c;
char *buf = NULL;
char *src = NULL;
int r = 0;
struct stat fdist;
c = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION);
if (LZ4F_isError(c))
{
log_debug("Failed to initialized LZ4: %s", LZ4F_getErrorName(c));
r = -ENOMEM;
goto cleanup;
}
buf = malloc(LZ4_DEC_BUF_SIZE);
if (!buf)
{
r = -errno;
goto cleanup;
}
if (fstat(fdi, &fdist) < 0)
{
r = -errno;
log_debug("Failed to stat the input fd");
goto cleanup;
}
src = mmap(NULL, fdist.st_size, PROT_READ, MAP_PRIVATE, fdi, 0);
if (!src)
{
r = -errno;
log_debug("Failed to mmap the input fd");
goto cleanup;
}
off_t total_in = 0;
while (fdist.st_size != total_in)
{
size_t used = fdist.st_size - total_in;
size_t produced = LZ4_DEC_BUF_SIZE;
c = LZ4F_decompress(ctx, buf, &produced, src + total_in, &used, NULL);
if (LZ4F_isError(c))
{
log_debug("Failed to decode LZ4 block: %s", LZ4F_getErrorName(c));
r = -EBADMSG;
goto cleanup;
}
r = safe_write(fdo, buf, produced);
if (r < 0)
{
log_debug("Failed to write decoded block");
goto cleanup;
}
total_in += used;
}
r = 0;
cleanup:
if (ctx != NULL)
LZ4F_freeDecompressionContext(ctx);
if (buf != NULL)
free(buf);
if (src != NULL)
munmap(src, fdist.st_size);
return r;
#else /*HAVE_LZ4*/
const char *cmd[] = { "lz4", "-cd", "-", NULL};
return decompress_using_fork_execvp(cmd, fdi, fdo);
#endif /*HAVE_LZ4*/
}
开发者ID:abrt,项目名称:libreport,代码行数:84,代码来源:compress.c
示例10: fcgi_read_request
//.........这里部分代码省略.........
len = (hdr.contentLengthB1 << 8) | hdr.contentLengthB0;
padding = hdr.paddingLength;
while (hdr.type == FCGI_STDIN && len == 0) {
if (safe_read(req, &hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) ||
hdr.version < FCGI_VERSION_1) {
return 0;
}
len = (hdr.contentLengthB1 << 8) | hdr.contentLengthB0;
padding = hdr.paddingLength;
}
req->id = (hdr.requestIdB1 << 8) + hdr.requestIdB0;
if (hdr.type == FCGI_BEGIN_REQUEST && len == sizeof(fcgi_begin_request)) {
char *val;
if (safe_read(req, buf, len+padding) != len+padding) {
return 0;
}
req->keep = (((fcgi_begin_request*)buf)->flags & FCGI_KEEP_CONN);
switch ((((fcgi_begin_request*)buf)->roleB1 << 8) + ((fcgi_begin_request*)buf)->roleB0) {
case FCGI_RESPONDER:
val = strdup("RESPONDER");
zend_hash_update(&req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL);
break;
case FCGI_AUTHORIZER:
val = strdup("AUTHORIZER");
zend_hash_update(&req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL);
break;
case FCGI_FILTER:
val = strdup("FILTER");
zend_hash_update(&req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL);
break;
default:
return 0;
}
if (safe_read(req, &hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) ||
hdr.version < FCGI_VERSION_1) {
return 0;
}
len = (hdr.contentLengthB1 << 8) | hdr.contentLengthB0;
padding = hdr.paddingLength;
while (hdr.type == FCGI_PARAMS && len > 0) {
if (safe_read(req, buf, len+padding) != len+padding) {
req->keep = 0;
return 0;
}
if (!fcgi_get_params(req, buf, buf+len)) {
req->keep = 0;
return 0;
}
if (safe_read(req, &hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) ||
hdr.version < FCGI_VERSION_1) {
req->keep = 0;
return 0;
}
len = (hdr.contentLengthB1 << 8) | hdr.contentLengthB0;
padding = hdr.paddingLength;
}
} else if (hdr.type == FCGI_GET_VALUES) {
int j;
unsigned char *p = buf + sizeof(fcgi_header);
if (safe_read(req, buf, len+padding) != len+padding) {
req->keep = 0;
return 0;
}
if (!fcgi_get_params(req, buf, buf+len)) {
req->keep = 0;
return 0;
}
for (j = 0; j < sizeof(fcgi_mgmt_vars)/sizeof(fcgi_mgmt_vars[0]); j++) {
if (zend_hash_exists(&req->env, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].name_len+1) == 0) {
sprintf((char*)p, "%c%c%s%c", fcgi_mgmt_vars[j].name_len, 1, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].val);
p += fcgi_mgmt_vars[j].name_len + 3;
}
}
len = p - buf - sizeof(fcgi_header);
len += fcgi_make_header((fcgi_header*)buf, FCGI_GET_VALUES_RESULT, 0, len);
if (safe_write(req, buf, sizeof(fcgi_header)+len) != (int)sizeof(fcgi_header)+len) {
req->keep = 0;
return 0;
}
return 0;
} else {
return 0;
}
return 1;
}
开发者ID:hsomesun,项目名称:dezend,代码行数:101,代码来源:fastcgi.c
示例11: fcgi_write
int fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, int len)
{
int limit, rest;
if (len <= 0) {
return 0;
}
if (req->out_hdr && req->out_hdr->type != type) {
close_packet(req);
}
#if 0
/* Unoptimized, but clear version */
rest = len;
while (rest > 0) {
limit = sizeof(req->out_buf) - (req->out_pos - req->out_buf);
if (!req->out_hdr) {
if (limit < sizeof(fcgi_header)) {
if (!fcgi_flush(req, 0)) {
return -1;
}
}
open_packet(req, type);
}
limit = sizeof(req->out_buf) - (req->out_pos - req->out_buf);
if (rest < limit) {
memcpy(req->out_pos, str, rest);
req->out_pos += rest;
return len;
} else {
memcpy(req->out_pos, str, limit);
req->out_pos += limit;
rest -= limit;
str += limit;
if (!fcgi_flush(req, 0)) {
return -1;
}
}
}
#else
/* Optimized version */
limit = sizeof(req->out_buf) - (req->out_pos - req->out_buf);
if (!req->out_hdr) {
limit -= sizeof(fcgi_header);
if (limit < 0) limit = 0;
}
if (len < limit) {
if (!req->out_hdr) {
open_packet(req, type);
}
memcpy(req->out_pos, str, len);
req->out_pos += len;
} else if (len - limit < sizeof(req->out_buf) - sizeof(fcgi_header)) {
if (!req->out_hdr) {
open_packet(req, type);
}
if (limit > 0) {
memcpy(req->out_pos, str, limit);
req->out_pos += limit;
}
if (!fcgi_flush(req, 0)) {
return -1;
}
if (len > limit) {
open_packet(req, type);
memcpy(req->out_pos, str + limit, len - limit);
req->out_pos += len - limit;
}
} else {
int pos = 0;
int pad;
close_packet(req);
while ((len - pos) > 0xffff) {
open_packet(req, type);
fcgi_make_header(req->out_hdr, type, req->id, 0xfff8);
req->out_hdr = NULL;
if (!fcgi_flush(req, 0)) {
return -1;
}
if (safe_write(req, str + pos, 0xfff8) != 0xfff8) {
req->keep = 0;
return -1;
}
pos += 0xfff8;
}
pad = (((len - pos) + 7) & ~7) - (len - pos);
rest = pad ? 8 - pad : 0;
open_packet(req, type);
fcgi_make_header(req->out_hdr, type, req->id, (len - pos) - rest);
req->out_hdr = NULL;
if (!fcgi_flush(req, 0)) {
return -1;
}
if (safe_write(req, str + pos, (len - pos) - rest) != (len - pos) - rest) {
req->keep = 0;
//.........这里部分代码省略.........
开发者ID:hsomesun,项目名称:dezend,代码行数:101,代码来源:fastcgi.c
示例12: recv_sideband
int recv_sideband(const char *me, int in_stream, int out, int err)
{
unsigned pf = strlen(PREFIX);
unsigned sf;
char buf[LARGE_PACKET_MAX + 2*FIX_SIZE];
char *suffix, *term;
int skip_pf = 0;
memcpy(buf, PREFIX, pf);
term = getenv("TERM");
if (term && strcmp(term, "dumb"))
suffix = ANSI_SUFFIX;
else
suffix = DUMB_SUFFIX;
sf = strlen(suffix);
while (1) {
int band, len;
len = packet_read_line(in_stream, buf + pf, LARGE_PACKET_MAX);
if (len == 0)
break;
if (len < 1) {
len = sprintf(buf, "%s: protocol error: no band designator\n", me);
safe_write(err, buf, len);
return SIDEBAND_PROTOCOL_ERROR;
}
band = buf[pf] & 0xff;
len--;
switch (band) {
case 3:
buf[pf] = ' ';
buf[pf+1+len] = '\n';
safe_write(err, buf, pf+1+len+1);
return SIDEBAND_REMOTE_ERROR;
case 2:
buf[pf] = ' ';
do {
char *b = buf;
int brk = 0;
/*
* If the last buffer didn't end with a line
* break then we should not print a prefix
* this time around.
*/
if (skip_pf) {
b += pf+1;
} else {
len += pf+1;
brk += pf+1;
}
/* Look for a line break. */
for (;;) {
brk++;
if (brk > len) {
brk = 0;
break;
}
if (b[brk-1] == '\n' ||
b[brk-1] == '\r')
break;
}
/*
* Let's insert a suffix to clear the end
* of the screen line if a line break was
* found. Also, if we don't skip the
* prefix, then a non-empty string must be
* present too.
*/
if (brk > (skip_pf ? 0 : (pf+1 + 1))) {
char save[FIX_SIZE];
memcpy(save, b + brk, sf);
b[brk + sf - 1] = b[brk - 1];
memcpy(b + brk - 1, suffix, sf);
safe_write(err, b, brk + sf);
memcpy(b + brk, save, sf);
len -= brk;
} else {
int l = brk ? brk : len;
safe_write(err, b, l);
len -= l;
}
skip_pf = !brk;
memmove(buf + pf+1, b + brk, len);
} while (len);
continue;
case 1:
safe_write(out, buf + pf+1, len);
continue;
default:
len = sprintf(buf,
"%s: protocol error: bad band #%d\n",
me, band);
safe_write(err, buf, len);
return SIDEBAND_PROTOCOL_ERROR;
}
}
//.........这里部分代码省略.........
开发者ID:Inkdit,项目名称:git,代码行数:101,代码来源:sideband.c
示例13: main
//.........这里部分代码省略.........
udp_packet tmp;
struct sockaddr_in mon_side;
/* ricezione dei dal monitor */
general_recvfrom((int32_t *) &(tmp), sizeof(udp_packet), udp_gate, &mon_side);
if (check_port(port_list, ntohs(mon_side.sin_port)) == FALSE) /* inserimento di una, forse, nuova porta monitor */
insert_port(&port_list, ntohs(mon_side.sin_port));
switch (tmp.type_packet) {
case STANDARD: {
#ifdef O_DEBUG
printf("id pacchetto ricevuto: %d\n", tmp.id_packet);
#endif
up_packets[BUFF_PACK_SIZE - 1].udp_data = tmp; /* speranza che sia vuoto per la legge di Gigio */
gettimeofday(&(up_packets[BUFF_PACK_SIZE - 1].delivered), NULL);
if ((actual_zero.tv_usec == 0) && (actual_zero.tv_sec == 0)) /* nuovo zero dell'opposto balancer */
i_2_s(s_2_i(&(up_packets[BUFF_PACK_SIZE - 1].delivered)) - (INTER_PACKET * tmp.id_packet), &actual_zero);
mighty_f_revenge(up_packets, BUFF_PACK_SIZE - 1, &actual_zero, 0);
if (tmp.id_packet == (last_uploaded + 1)) { /* e' il successivo */
clear_pack(up_packets, BUFF_PACK_SIZE - 1);
to_app_packets[index_udpfree_pack(to_app_packets)] = tmp;
last_uploaded = tmp.id_packet; /* aggiorno ultimo upload */
check_inline_pack(up_packets, to_app_packets, &last_uploaded, tmp.id_packet);
FD_SET(new_app_fd, &writefds);
}
else {
if (tmp.id_packet > last_uploaded) {
sort_buffer(up_packets);
}
else /* in ritado abissale, drop */
clear_pack(up_packets, BUFF_PACK_SIZE - 1);
}
break;
}
default : { /* pacchetto di notifica */
port_monitoring *ptmp = NULL;
stat_notify *trick = (stat_notify*) &tmp;
#ifdef O_DEBUG_N
printf("pacchetto id: %d\n", tmp.id_packet);
printf("pacchetto di notifica con porta id: %d\n", trick->id_port);
#endif
if ((last_notify < trick->id_notify) || (last_seq == trick->id_sequence)) { /* non e' in ritardo abissale */
if ((trick->id_sequence < last_seq) || (trick->id_sequence > last_seq)) { /* nuova sequenza di notifiche */
m_id_ports.message = trick->type_packet - NOTIFY_F;
last_seq = trick->id_sequence;
}
last_notify = trick->id_notify;
m_id_ports.message--; /* nuova notifica della stessa sequenza, decrementa contatore */
m_id_ports.ports[m_id_ports.message] = trick->id_port + 1000;
ptmp = find_port(port_list, trick->id_port + 1000); /* abbiamo spedito ID lato mobile, vogliamo quello fixed */
if (ptmp == NULL) { /* porta di cui il fixed non era a conoscenza */
if (m_id_ports.message == 0) {
/* non ci sono piu' pacchetti di notifica, costruzione della lista delle porte aperte
* e reset-default per la prossima volta */
m_id_ports.message = trick->type_packet - NOTIFY_F; /* lunghezza lista porte del mobile */
build_act_ports(&port_list, &m_id_ports);
m_id_ports.message = 0; /* reset per la prossima notifica */
break;
}
insert_port(&port_list, trick->id_port + 1000);
break; /* esce forzatamente dallo switch */
}
ptmp->not_to_fixed = *trick; /* aggiorna la notifica */
ptmp->last_tot_packets = ptmp->tot_packets - ptmp->medium_tot_packets;
good_percentual = partial_pp_lost(port_list);
ptmp->ack_packets += ptmp->not_to_fixed.n_received;
ptmp->nack_packets = ptmp->tot_packets - ptmp->ack_packets;
ptmp->medium_tot_packets = ptmp->tot_packets;
mighty_f_ports(&port_list); /* calcolo performance delle porte */
if (m_id_ports.message == 0) {
/* non ci sono piu' pacchetti di notifica, costruzione della lista delle porte aperte
* e reset-default per la prossima volta */
m_id_ports.message = trick->type_packet - NOTIFY_F; /* lunghezza lista porte del mobile */
build_act_ports(&port_list, &m_id_ports);
m_id_ports.message = 0; /* reset per la prossima notifica */
}
}
}
}
}
if (FD_ISSET(new_app_fd, &s_writefds)) {
memcpy(data_app_fixed, &(to_app_packets[0].id_packet), sizeof(uint32_t));
memcpy(&(data_app_fixed[4]), &(to_app_packets[0].data), DATA_BUFF_SIZE - sizeof(uint32_t));
safe_write(new_app_fd, DATA_BUFF_SIZE, data_app_fixed);
udp_shift_pack(to_app_packets, 0); /* clear e shift */
if (to_app_packets[0].type_packet == FALSE) /* non ce ne sono piu' */
FD_CLR(new_app_fd, &writefds);
}
if (nready == 0) { /* timeout espirato, nessun fd pronto */
if (check_inline_pack(up_packets, to_app_packets, &last_uploaded, up_packets[0].udp_data.id_packet - 1))
FD_SET(new_app_fd, &writefds);
}
index_to = BUFF_PACK_SIZE;
timeout.tv_sec = timeout.tv_usec = 0;
index_to = manage_timeout(up_packets, &timeout);
}
return 0;
}
开发者ID:LuigiPomili,项目名称:QoS-VoIP-MultiHoming,代码行数:101,代码来源:fixedLB.c
示例14: _handle_suspend
static int
_handle_suspend(int fd, slurmd_job_t *job, uid_t uid)
{
int rc = SLURM_SUCCESS;
int errnum = 0;
debug("_handle_suspend for job %u.%u",
job->jobid, job->stepid);
debug3(" uid = %d", uid);
if (!_slurm_authorized_user(uid)) {
debug("job step suspend request from uid %ld for job %u.%u ",
(long)uid, job->jobid, job->stepid);
rc = -1;
errnum = EPERM;
goto done;
}
if (job->cont_id == 0) {
debug ("step %u.%u invalid container [cont_id:%"PRIu64"]",
job->jobid, job->stepid, job->cont_id);
rc = -1;
errnum = ESLURMD_JOB_NOTRUNNING;
goto done;
}
jobacct_gather_g_suspend_poll();
/*
* Signal the container
*/
pthread_mutex_lock(&suspend_mutex);
if (suspended) {
rc = -1;
errnum = ESLURMD_STEP_SUSPENDED;
pthread_mutex_unlock(&suspend_mutex);
goto done;
} else {
/* SIGTSTP is sent first to let MPI daemons stop their tasks,
* then wait 2 seconds, then send SIGSTOP to the spawned
* process's container to stop everything else.
*
* In some cases, 1 second has proven insufficient. Longer
* delays may help insure that all MPI tasks have been stopped
* (that depends upon the MPI implementaiton used), but will
* also permit longer time periods when more than one job can
* be running on each resource (not good). */
if (slurm_container_signal(job->cont_id, SIGTSTP) < 0) {
verbose("Error suspending %u.%u (SIGTSTP): %m",
job->jobid, job->stepid);
} else
sleep(2);
if (slurm_container_signal(job->cont_id, SIGSTOP) < 0) {
verbose("Error suspending %u.%u (SIGSTOP): %m",
job->jobid, job->stepid);
} else {
verbose("Suspended %u.%u", job->jobid, job->stepid);
}
suspended = true;
}
pthread_mutex_unlock(&suspend_mutex);
done:
/* Send the return code and errno */
safe_write(fd, &rc, sizeof(int));
safe_write(fd, &errnum, sizeof(int));
return SLURM_SUCCESS;
rwfail:
return SLURM_FAILURE;
}
开发者ID:lipari,项目名称:slurm,代码行数:71,代码来源:req.c
示例15: _proc_stdout
/*
* Process TaskProlog output
* "export NAME=value" adds environment variables
* "unset NAME" clears an environment variable
* "print <whatever>" writes that to the job's stdout
*/
static void _proc_stdout(char *buf, stepd_step_rec_t *job)
{
bool end_buf = false;
int len;
char *buf_ptr, *name_ptr, *val_ptr;
char *end_line, *equal_ptr;
char ***env = &job->env;
buf_ptr = buf;
while (buf_ptr[0]) {
end_line = strchr(buf_ptr, '\n');
if (!end_line) {
end_line = buf_ptr + strlen(buf_ptr);
end_buf = true;
}
if (!strncmp(buf_ptr, "print ", 6)) {
buf_ptr += 6;
while (isspace(buf_ptr[0]))
buf_ptr++;
len = end_line - buf_ptr + 1;
safe_write(1, buf_ptr, len);
} else if (!strncmp(buf_ptr, "export ",7)) {
name_ptr = buf_ptr + 7;
while (isspace(name_ptr[0]))
name_ptr++;
equal_ptr = strchr(name_ptr, '=');
if (!equal_ptr || (equal_ptr > end_line))
goto rwfail;
val_ptr = equal_ptr + 1;
while (isspace(equal_ptr[-1]))
equal_ptr--;
equal_ptr[0] = '\0';
end_line[0] = '\0';
if (!strcmp(name_ptr, "SLURM_PROLOG_CPU_MASK")) {
job->cpu_bind_type = CPU_BIND_MASK;
xfree(job->cpu_bind);
job->cpu_bind = xstrdup(val_ptr);
if (task_g_pre_launch(job)) {
error("Failed SLURM_PROLOG_CPU_MASK "
"setup");
exit(1);
}
}
debug("export name:%s:val:%s:", name_ptr, val_ptr);
if (setenvf(env, name_ptr, "%s", val_ptr)) {
error("Unable to set %s environment variable",
buf_ptr);
}
equal_ptr[0] = '=';
if (end_buf)
end_line[0] = '\0';
else
end_line[0] = '\n';
} else if (!strncmp(buf_ptr, "unset ", 6)) {
name_ptr = buf_ptr + 6;
while (isspace(name_ptr[0]))
name_ptr++;
if ((name_ptr[0] == '\n') || (name_ptr[0] == '\0'))
goto rwfail;
while (isspace(end_line[-1]))
end_line--;
end_line[0] = '\0';
debug(" unset name:%s:", name_ptr);
unsetenvp(*env, name_ptr);
if (end_buf)
end_line[0] = '\0';
else
end_line[0] = '\n';
}
rwfail: /* process rest of script output */
if (end_buf)
break;
buf_ptr = end_line + 1;
}
return;
}
开发者ID:npe9,项目名称:slurm,代码行数:83,代码来源:task.c
示例16: _handle_signal_process_group
static int
_handle_signal_process_group(int fd, slurmd_job_t *job, uid_t uid)
{
int rc = SLURM_SUCCESS;
int signal;
debug3("_handle_signal_process_group for job %u.%u",
job->jobid, job->stepid);
safe_read(fd, &signal, sizeof(int));
debug3(" uid = %d", uid);
if (uid != job->uid && !_slurm_authorized_user(uid)) {
debug("kill req from uid %ld for job %u.%u owned by uid %ld",
(long)uid, job->jobid, job->stepid, (long)job->uid);
rc = EPERM;
goto done;
}
/*
* Sanity checks
*/
if (job->pgid <= (pid_t)1) {
debug ("step %u.%u invalid [jmgr_pid:%d pgid:%u]",
job->jobid, job->stepid, job->jmgr_pid, job->pgid);
rc = ESLURMD_JOB_NOTRUNNING;
goto done;
}
/*
* Signal the process group
*/
pthread_mutex_lock(&suspend_mutex);
if (suspended && (signal != SIGKILL)) {
rc = ESLURMD_STEP_SUSPENDED;
pthread_mutex_unlock(&suspend_mutex);
goto d
|
请发表评论