view toys/posix/nohup.c @ 1183:0752b2d58909 draft

Rename xmsprintf() to just xmprintf(). Partly because there's no supplied target string ala sprintf, and partly because I can never remember what order the m and s go in.
author Rob Landley <>
date Thu, 16 Jan 2014 09:26:50 -0600
parents 144d5ba7d410
children 76965793e8f4
line wrap: on
line source

/* nohup.c - run commandline with SIGHUP blocked.
 * Copyright 2011 Rob Landley <>
 * See


config NOHUP
  bool "nohup"
  default y
    usage: nohup COMMAND [ARGS...]

    Run a command that survives the end of its terminal.
    If stdin is a tty, redirect from /dev/null
    If stdout is a tty, redirect to file "nohup.out"

#include "toys.h"

void nohup_main(void)
  signal(SIGHUP, SIG_IGN);
  if (isatty(1)) {
    if (-1 == open("nohup.out", O_CREAT|O_APPEND|O_WRONLY,
        S_IRUSR|S_IWUSR ))
      char *temp = getenv("HOME");
      temp = xmprintf("%s/%s", temp ? temp : "", "nohup.out");
      xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
  if (isatty(0)) {
    open("/dev/null", O_RDONLY);