/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugins.d/usplash.c

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * along with this program.  If not, see
20
20
 * <http://www.gnu.org/licenses/>.
21
21
 * 
22
 
 * Contact the authors at <https://www.fukt.bsnet.se/~belorn/> and
23
 
 * <https://www.fukt.bsnet.se/~teddy/>.
 
22
 * Contact the authors at <mandos@fukt.bsnet.se>.
24
23
 */
25
24
 
26
25
#define _GNU_SOURCE             /* asprintf() */
64
63
   */
65
64
  int ret;
66
65
  int fifo_fd;
67
 
  do{
 
66
  do {
68
67
    fifo_fd = open("/dev/.initramfs/usplash_fifo", O_WRONLY);
69
68
    if((fifo_fd == -1) and (errno != EINTR or interrupted_by_signal)){
70
69
      return false;
71
70
    }
72
 
  }while(fifo_fd == -1);
 
71
  } while(fifo_fd == -1);
73
72
  
74
73
  const char *cmd_line;
75
74
  size_t cmd_line_len;
77
76
  if(arg == NULL){
78
77
    cmd_line = cmd;
79
78
    cmd_line_len = strlen(cmd);
80
 
  }else{
81
 
    do{
 
79
  } else {
 
80
    do {
82
81
      ret = asprintf(&cmd_line_alloc, "%s %s", cmd, arg);
83
82
      if(ret == -1 and (errno != EINTR or interrupted_by_signal)){
84
83
        int e = errno;
86
85
        errno = e;
87
86
        return false;
88
87
      }
89
 
    }while(ret == -1);
 
88
    } while(ret == -1);
90
89
    cmd_line = cmd_line_alloc;
91
90
    cmd_line_len = (size_t)ret + 1;
92
91
  }
110
109
    written += (size_t)sret;
111
110
  }
112
111
  free(cmd_line_alloc);
113
 
  do{
 
112
  do {
114
113
    ret = close(fifo_fd);
115
114
    if(ret == -1 and (errno != EINTR or interrupted_by_signal)){
116
115
      return false;
117
116
    }
118
 
  }while(ret == -1);
 
117
  } while(ret == -1);
119
118
  if(interrupted_by_signal){
120
119
    return false;
121
120
  }
252
251
          size_t cmdline_allocated = 0;
253
252
          char *tmp;
254
253
          const size_t blocksize = 1024;
255
 
          do{
 
254
          do {
256
255
            if(cmdline_len + blocksize > cmdline_allocated){
257
256
              tmp = realloc(cmdline, cmdline_allocated + blocksize);
258
257
              if(tmp == NULL){
366
365
    
367
366
    /* Open FIFO */
368
367
    int fifo_fd;
369
 
    do{
 
368
    do {
370
369
      fifo_fd = open("/dev/.initramfs/usplash_outfifo", O_RDONLY);
371
370
      if(fifo_fd == -1){
372
371
        if(errno != EINTR){
378
377
          break;
379
378
        }
380
379
      }
381
 
    }while(fifo_fd == -1);
 
380
    } while(fifo_fd == -1);
382
381
    if(interrupted_by_signal or an_error_occured){
383
382
      break;                    /* Big */
384
383
    }
386
385
    /* Read from FIFO */
387
386
    size_t buf_allocated = 0;
388
387
    const size_t blocksize = 1024;
389
 
    do{
 
388
    do {
390
389
      if(buf_len + blocksize > buf_allocated){
391
390
        char *tmp = realloc(buf, buf_allocated + blocksize);
392
391
        if(tmp == NULL){
397
396
        buf = tmp;
398
397
        buf_allocated += blocksize;
399
398
      }
400
 
      do{
 
399
      do {
401
400
        sret = read(fifo_fd, buf + buf_len, buf_allocated - buf_len);
402
401
        if(sret == -1){
403
402
          if(errno != EINTR){
409
408
            break;
410
409
          }
411
410
        }
412
 
      }while(sret == -1);
 
411
      } while(sret == -1);
413
412
      if(interrupted_by_signal or an_error_occured){
414
413
        break;
415
414
      }
416
415
      
417
416
      buf_len += (size_t)sret;
418
 
    }while(sret != 0);
 
417
    } while(sret != 0);
419
418
    close(fifo_fd);
420
419
    if(interrupted_by_signal or an_error_occured){
421
420
      break;                    /* Big */
433
432
    /* Print password to stdout */
434
433
    size_t written = 0;
435
434
    while(written < buf_len){
436
 
      do{
 
435
      do {
437
436
        sret = write(STDOUT_FILENO, buf + written, buf_len - written);
438
437
        if(sret == -1){
439
438
          if(errno != EINTR){
445
444
            break;
446
445
          }
447
446
        }
448
 
      }while(sret == -1);
 
447
      } while(sret == -1);
449
448
      if(interrupted_by_signal or an_error_occured){
450
449
        break;
451
450
      }