~ubuntu-branches/ubuntu/vivid/slurm-llnl/vivid

« back to all changes in this revision

Viewing changes to src/api/step_io.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2009-09-24 23:28:15 UTC
  • mfrom: (1.1.11 upstream) (3.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090924232815-enh65jn32q1ebg07
Tags: 2.0.5-1
* New upstream release 
* Changed dependecy from lib-mysqlclient15 to lib-mysqlclient 
* Added Default-Start for runlevel 2 and 4 and $remote_fs requirement in
  init.d scripts (Closes: #541252)
* Postinst checks for wrong runlevels 2 and 4 links
* Upgraded to standard version 3.8.3
* Add lintian overrides for missing slurm-llnl-configurator.html in doc
  base registration
* modified postrm scripts to ignore pkill return value in order to avoid
  postrm failure when no slurm process is running
* Checking for slurmctld.pid before cancelling running and pending
  jobs during package removal 

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 *  LLNL-CODE-402394.
 
8
 *  CODE-OCEC-09-009. All rights reserved.
9
9
 *  
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.
12
13
 *  
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
57
58
#include "src/common/eio.h"
58
59
#include "src/common/io_hdr.h"
59
60
#include "src/common/net.h"
 
61
#include "src/common/write_labelled_message.h"
60
62
 
61
63
#include "src/api/step_io.h"
62
64
 
490
492
        return eio;
491
493
}
492
494
 
493
 
static int _write_label(int fd, int taskid, int label_width)
494
 
{
495
 
        int n;
496
 
        int left = label_width + 2;
497
 
        char buf[16];
498
 
        void *ptr = buf;
499
 
 
500
 
        snprintf(buf, 16, "%0*d: ", label_width, taskid);
501
 
        while (left > 0) {
502
 
        again:
503
 
                if ((n = write(fd, ptr, left)) < 0) {
504
 
                        if (errno == EINTR)
505
 
                                goto again;
506
 
                        if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
507
 
                                debug3("  got EAGAIN in _write_label");
508
 
                                goto again;
509
 
                        }
510
 
                        error("In _write_label: %m");
511
 
                        return SLURM_ERROR;
512
 
                }
513
 
                left -= n;
514
 
                ptr += n;
515
 
        }
516
 
 
517
 
        return SLURM_SUCCESS;
518
 
}
519
 
 
520
 
static int _write_newline(int fd)
521
 
{
522
 
        int n;
523
 
 
524
 
        debug2("Called _write_newline");
525
 
again:
526
 
        if ((n = write(fd, "\n", 1)) < 0) {
527
 
                if (errno == EINTR
528
 
                    || errno == EAGAIN
529
 
                    || errno == EWOULDBLOCK) {
530
 
                        goto again;
531
 
                }
532
 
                error("In _write_newline: %m");
533
 
                return SLURM_ERROR;
534
 
        }
535
 
        return SLURM_SUCCESS;
536
 
}
537
 
 
538
 
/*
539
 
 * Blocks until write is complete, regardless of the file
540
 
 * descriptor being in non-blocking mode.
541
 
 */
542
 
static int _write_line(int fd, void *buf, int len)
543
 
{
544
 
        int n;
545
 
        int left = len;
546
 
        void *ptr = buf;
547
 
 
548
 
        debug2("Called _write_line");
549
 
        while (left > 0) {
550
 
        again:
551
 
                if ((n = write(fd, ptr, left)) < 0) {
552
 
                        if (errno == EINTR)
553
 
                                goto again;
554
 
                        if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
555
 
                                debug3("  got EAGAIN in _write_line");
556
 
                                goto again;
557
 
                        }
558
 
                        return -1;
559
 
                }
560
 
                left -= n;
561
 
                ptr += n;
562
 
        }
563
 
        
564
 
        return len;
565
 
}
566
 
 
567
 
 
568
 
/*
569
 
 * Write as many lines from the message as possible.  Return
570
 
 * the number of bytes from the message that have been written,
571
 
 * or -1 on error.
572
 
 *
573
 
 * Prepend a label of the task number if label parameter was
574
 
 * specified.
575
 
 *
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
578
 
 * in label mode.
579
 
 */
580
 
static int _write_msg(int fd, void *buf, int len, int taskid,
581
 
                      bool label, int label_width)
582
 
{
583
 
        void *start;
584
 
        void *end;
585
 
        int remaining = len;
586
 
        int written = 0;
587
 
        int line_len;
588
 
        int rc = -1;
589
 
 
590
 
        while (remaining > 0) {
591
 
                start = buf + written;
592
 
                end = memchr(start, '\n', remaining);
593
 
                if (label)
594
 
                        if (_write_label(fd, taskid, label_width)
595
 
                            != SLURM_SUCCESS)
596
 
                                goto done;
597
 
                if (end == NULL) { /* no newline found */
598
 
                        rc = _write_line(fd, start, remaining);
599
 
                        if (rc <= 0) {
600
 
                                goto done;
601
 
                        } else {
602
 
                                remaining -= rc;
603
 
                                written += rc;
604
 
                        }
605
 
                        if (label)
606
 
                                if (_write_newline(fd) != SLURM_SUCCESS)
607
 
                                        goto done;
608
 
                } else {
609
 
                        line_len = (int)(end - start) + 1;
610
 
                        rc = _write_line(fd, start, line_len);
611
 
                        if (rc <= 0) {
612
 
                                goto done;
613
 
                        } else {
614
 
                                remaining -= rc;
615
 
                                written += rc;
616
 
                        }
617
 
                }
618
 
 
619
 
        }
620
 
done:
621
 
        if (written > 0)
622
 
                return written;
623
 
        else
624
 
                return rc;
625
 
}
626
495
 
627
496
static bool _file_writable(eio_obj_t *obj)
628
497
{
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,
671
 
                                    info->out_remaining,
672
 
                                    info->out_msg->header.gtaskid,
673
 
                                    info->cio->label,
674
 
                                    info->cio->label_width)) < 0) {
 
539
                if ((n = write_labelled_message(obj->fd, ptr,
 
540
                                                info->out_remaining,
 
541
                                                info->out_msg->header.gtaskid,
 
542
                                                info->cio->label,
 
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;