source: trunk/third-party/shttpd/standalone.c @ 6644

Last change on this file since 6644 was 6644, checked in by charles, 13 years ago

upgrade to shttpd 1.42

File size: 1.7 KB
Line 
1/*
2 * Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
3 * All rights reserved
4 *
5 * "THE BEER-WARE LICENSE" (Revision 42):
6 * Sergey Lyubka wrote this file.  As long as you retain this notice you
7 * can do whatever you want with this stuff. If we meet some day, and you think
8 * this stuff is worth it, you can buy me a beer in return.
9 */
10
11#include "defs.h"
12
13static int      exit_flag;      /* Program termination flag     */
14
15static void
16signal_handler(int sig_num)
17{
18        switch (sig_num) {
19#ifndef _WIN32
20        case SIGCHLD:
21                while (waitpid(-1, &sig_num, WNOHANG) > 0) ;
22                break;
23#endif /* !_WIN32 */
24        default:
25                exit_flag = sig_num;
26                break;
27        }
28}
29
30int
31main(int argc, char *argv[])
32{
33        struct shttpd_ctx       *ctx;
34
35#if !defined(NO_AUTH)
36        if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'A') {
37                if (argc != 6)
38                        _shttpd_usage(argv[0]);
39                exit(_shttpd_edit_passwords(argv[2],argv[3],argv[4],argv[5]));
40        }
41#endif /* NO_AUTH */
42
43        if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
44                _shttpd_usage(argv[0]);
45
46#if defined(_WIN32)
47        try_to_run_as_nt_service();
48#endif /* _WIN32 */
49
50#ifndef _WIN32
51        (void) signal(SIGCHLD, signal_handler);
52        (void) signal(SIGPIPE, SIG_IGN);
53#endif /* _WIN32 */
54
55        (void) signal(SIGTERM, signal_handler);
56        (void) signal(SIGINT, signal_handler);
57
58        if ((ctx = shttpd_init(argc, argv)) == NULL)
59                _shttpd_elog(E_FATAL, NULL, "%s",
60                    "Cannot initialize SHTTPD context");
61
62        _shttpd_elog(E_LOG, NULL, "shttpd %s started on port(s) %s, serving %s",
63            VERSION, ctx->options[OPT_PORTS], ctx->options[OPT_ROOT]);
64
65        while (exit_flag == 0)
66                shttpd_poll(ctx, 10 * 1000);
67
68        _shttpd_elog(E_LOG, NULL, "Exit on signal %d", exit_flag);
69        shttpd_fini(ctx);
70
71        return (EXIT_SUCCESS);
72}
Note: See TracBrowser for help on using the repository browser.