1
1
/****************************************************************************\
2
2
* step_io.c - process stdin, stdout, and stderr for parallel jobs.
3
* $Id: step_io.c 13672 2008-03-19 23:10:58Z jette $
3
* $Id: step_io.c 17056 2009-03-26 23:35:52Z dbremer $
4
4
*****************************************************************************
5
5
* Copyright (C) 2006 The Regents of the University of California.
6
6
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
7
7
* Written by Mark Grondona <grondona@llnl.gov>, et. al.
8
* CODE-OCEC-09-009. All rights reserved.
10
10
* This file is part of SLURM, a resource management program.
11
* For details, see <http://www.llnl.gov/linux/slurm/>.
11
* For details, see <https://computing.llnl.gov/linux/slurm/>.
12
* Please also read the included file: DISCLAIMER.
13
14
* SLURM is free software; you can redistribute it and/or modify it under
14
15
* the terms of the GNU General Public License as published by the Free
493
static int _write_label(int fd, int taskid, int label_width)
496
int left = label_width + 2;
500
snprintf(buf, 16, "%0*d: ", label_width, taskid);
503
if ((n = write(fd, ptr, left)) < 0) {
506
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
507
debug3(" got EAGAIN in _write_label");
510
error("In _write_label: %m");
517
return SLURM_SUCCESS;
520
static int _write_newline(int fd)
524
debug2("Called _write_newline");
526
if ((n = write(fd, "\n", 1)) < 0) {
529
|| errno == EWOULDBLOCK) {
532
error("In _write_newline: %m");
535
return SLURM_SUCCESS;
539
* Blocks until write is complete, regardless of the file
540
* descriptor being in non-blocking mode.
542
static int _write_line(int fd, void *buf, int len)
548
debug2("Called _write_line");
551
if ((n = write(fd, ptr, left)) < 0) {
554
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
555
debug3(" got EAGAIN in _write_line");
569
* Write as many lines from the message as possible. Return
570
* the number of bytes from the message that have been written,
573
* Prepend a label of the task number if label parameter was
576
* If the message ends in a partial line (line does not end
577
* in a '\n'), then add a newline to the output file, but only
580
static int _write_msg(int fd, void *buf, int len, int taskid,
581
bool label, int label_width)
590
while (remaining > 0) {
591
start = buf + written;
592
end = memchr(start, '\n', remaining);
594
if (_write_label(fd, taskid, label_width)
597
if (end == NULL) { /* no newline found */
598
rc = _write_line(fd, start, remaining);
606
if (_write_newline(fd) != SLURM_SUCCESS)
609
line_len = (int)(end - start) + 1;
610
rc = _write_line(fd, start, line_len);
627
496
static bool _file_writable(eio_obj_t *obj)
667
536
} else if (!info->eof) {
668
537
ptr = info->out_msg->data + (info->out_msg->length
669
538
- info->out_remaining);
670
if ((n = _write_msg(obj->fd, ptr,
672
info->out_msg->header.gtaskid,
674
info->cio->label_width)) < 0) {
539
if ((n = write_labelled_message(obj->fd, ptr,
541
info->out_msg->header.gtaskid,
543
info->cio->label_width)) < 0) {
675
544
list_enqueue(info->cio->free_outgoing, info->out_msg);
676
545
info->eof = true;
677
546
return SLURM_ERROR;