File: cmd-sigpipe.c

package info (click to toggle)
remctl 3.18-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,612 kB
  • sloc: ansic: 19,504; sh: 5,386; perl: 1,778; java: 740; makefile: 715; xml: 502; python: 430
file content (35 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Small C program to verify that we get the default SIGPIPE behavior rather
 * than ignoring the signal.  This ensures that the server resets SIGPIPE
 * before running a command.
 *
 * Written by Russ Allbery <eagle@eyrie.org>
 * Copyright 2014
 *     The Board of Trustees of the Leland Stanford Junior University
 *
 * SPDX-License-Identifier: MIT
 */

#include <config.h>
#include <portable/system.h>

int
main(void)
{
    int fds[2];

    if (pipe(fds) < 0) {
        fprintf(stderr, "cannot create pipes\n");
        exit(1);
    }
    close(fds[0]);
    if (write(fds[1], "data", 4) < 0)
        fprintf(stderr, "write failed\n");

    /*
     * The previous call should cause a SIGPIPE signal and we should never
     * reach this code.
     */
    printf("no SIGPIPE seen");
    exit(0);
}