keepup

Check-in [7655803ffe]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Making getopt parse properly, using POSIXLY_CORRECT env var.

I took this code from ts/main.c.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7655803ffebbc6a7fde826e596dafa5fcf552ff5
User & Date: viric 2012-04-01 09:40:21
Original Comment: Making getopt parse properly, using POSIXLY_CORRECT env var.
Context
2012-04-01
09:52
Fixing 'stop' to FORK daemons (like dictd). check-in: d18f84eb6a user: viric tags: trunk
09:40
Making getopt parse properly, using POSIXLY_CORRECT env var.

I took this code from ts/main.c. check-in: 7655803ffe user: viric tags: trunk

2012-03-31
23:56
Commenting where I took the ptrace event macro from. check-in: eb8a6236cf user: viric tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to main.c.

20
21
22
23
24
25
26




27
28
29
30
31
32
33
static const struct msg voidmsg;

enum t_child_status child_status = PRESTART;

static int lastsignal;

int child_pid;





static void default_command_line()
{
    config.action = ACTION_START;
    config.type = FOREGROUND;
    config.logfile = "/dev/null";
    config.socketfile = 0;







>
>
>
>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
static const struct msg voidmsg;

enum t_child_status child_status = PRESTART;

static int lastsignal;

int child_pid;

/* Globals for the environment of getopt */
static char getopt_env[] = "POSIXLY_CORRECT=YES";
static char *old_getopt_env;

static void default_command_line()
{
    config.action = ACTION_START;
    config.type = FOREGROUND;
    config.logfile = "/dev/null";
    config.socketfile = 0;
49
50
51
52
53
54
55

















56
57
58
59
60
61
62
    exit(0);
}

static void get_command(int index, int argc, char **argv)
{
    config.command = &(argv[index]);
}


















static void parse_opts(int argc, char **argv)
{
    int c;
    int res;

    /* Parse options */







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    exit(0);
}

static void get_command(int index, int argc, char **argv)
{
    config.command = &(argv[index]);
}

static void set_getopt_env()
{
    old_getopt_env = getenv("POSIXLY_CORRECT");
    putenv(getopt_env);
}

static void unset_getopt_env()
{
    if (old_getopt_env == NULL)
    {
        /* Wipe the string from the environment */
        putenv("POSIXLY_CORRECT");
    }
    else
        sprintf(getopt_env, "POSIXLY_CORRECT=%s", old_getopt_env);
}

static void parse_opts(int argc, char **argv)
{
    int c;
    int res;

    /* Parse options */
625
626
627
628
629
630
631

632

633
634
635
636
637
638
639
        exit(1);
    }
}

int main(int argc, char **argv)
{
    default_command_line();

    parse_opts(argc, argv);


    prepare_unix_socket();

    if (config.action == ACTION_START)
    {
        start_program_and_leave_session();
        serve_requests();







>

>







646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
        exit(1);
    }
}

int main(int argc, char **argv)
{
    default_command_line();
    set_getopt_env();
    parse_opts(argc, argv);
    unset_getopt_env();

    prepare_unix_socket();

    if (config.action == ACTION_START)
    {
        start_program_and_leave_session();
        serve_requests();