mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-19 05:53:42 +00:00
keep original argv
This commit is contained in:
14
Makefile
14
Makefile
@@ -44,13 +44,13 @@ override CFLAGS += -DWITH_PTHREAD_NP
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
#WITH_SETPROCTITLE ?= 1
|
WITH_SETPROCTITLE ?= 1
|
||||||
#ifneq ($(call optbool,$(WITH_SETPROCTITLE)),)
|
ifneq ($(call optbool,$(WITH_SETPROCTITLE)),)
|
||||||
#ifeq ($(shell uname -s | tr A-Z a-z),linux)
|
ifeq ($(shell uname -s | tr A-Z a-z),linux)
|
||||||
#_LIBS += -lbsd
|
_LIBS += -lbsd
|
||||||
#endif
|
endif
|
||||||
#override CFLAGS += -DWITH_SETPROCTITLE
|
override CFLAGS += -DWITH_SETPROCTITLE
|
||||||
#endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ static void _install_signal_handlers(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
struct options_t *options;
|
||||||
struct device_t *dev;
|
struct device_t *dev;
|
||||||
struct encoder_t *encoder;
|
struct encoder_t *encoder;
|
||||||
struct stream_t *stream;
|
struct stream_t *stream;
|
||||||
@@ -105,8 +106,8 @@ int main(int argc, char *argv[]) {
|
|||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
|
|
||||||
LOGGING_INIT;
|
LOGGING_INIT;
|
||||||
|
|
||||||
A_THREAD_RENAME("main");
|
A_THREAD_RENAME("main");
|
||||||
|
options = options_init(argc, argv);
|
||||||
|
|
||||||
# ifdef WITH_GPIO
|
# ifdef WITH_GPIO
|
||||||
GPIO_INIT;
|
GPIO_INIT;
|
||||||
@@ -117,7 +118,7 @@ int main(int argc, char *argv[]) {
|
|||||||
stream = stream_init(dev, encoder);
|
stream = stream_init(dev, encoder);
|
||||||
server = http_server_init(stream);
|
server = http_server_init(stream);
|
||||||
|
|
||||||
if ((exit_code = parse_options(argc, argv, dev, encoder, server)) == 0) {
|
if ((exit_code = options_parse(options, dev, encoder, server)) == 0) {
|
||||||
# ifdef WITH_GPIO
|
# ifdef WITH_GPIO
|
||||||
GPIO_INIT_PINOUT;
|
GPIO_INIT_PINOUT;
|
||||||
# endif
|
# endif
|
||||||
@@ -153,6 +154,7 @@ int main(int argc, char *argv[]) {
|
|||||||
GPIO_SET_LOW(prog_running);
|
GPIO_SET_LOW(prog_running);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
options_destroy(options);
|
||||||
if (exit_code == 0) {
|
if (exit_code == 0) {
|
||||||
LOG_INFO("Bye-bye");
|
LOG_INFO("Bye-bye");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#ifdef WITH_OMX
|
#include <string.h>
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
@@ -212,7 +210,31 @@ static void _features(void);
|
|||||||
static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server);
|
static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server);
|
||||||
|
|
||||||
|
|
||||||
int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server) {
|
struct options_t *options_init(int argc, char *argv[]) {
|
||||||
|
struct options_t *options;
|
||||||
|
|
||||||
|
A_CALLOC(options, 1);
|
||||||
|
options->argc = argc;
|
||||||
|
options->argv = argv;
|
||||||
|
|
||||||
|
A_CALLOC(options->argv_copy, argc);
|
||||||
|
for (int index = 0; index < argc; ++index) {
|
||||||
|
assert(options->argv_copy[index] = strdup(argv[index]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
void options_destroy(struct options_t *options) {
|
||||||
|
for (int index = 0; index < options->argc; ++index) {
|
||||||
|
free(options->argv_copy[index]);
|
||||||
|
}
|
||||||
|
free(options->argv_copy);
|
||||||
|
free(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int options_parse(struct options_t *options, struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server) {
|
||||||
# define OPT_SET(_dest, _value) { \
|
# define OPT_SET(_dest, _value) { \
|
||||||
_dest = _value; \
|
_dest = _value; \
|
||||||
break; \
|
break; \
|
||||||
@@ -285,7 +307,7 @@ int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((ch = getopt_long(argc, argv, short_opts, _LONG_OPTS, NULL)) >= 0) {
|
while ((ch = getopt_long(options->argc, options->argv_copy, short_opts, _LONG_OPTS, NULL)) >= 0) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case _O_DEVICE: OPT_SET(dev->path, optarg);
|
case _O_DEVICE: OPT_SET(dev->path, optarg);
|
||||||
case _O_INPUT: OPT_NUMBER("--input", dev->input, 0, 128, 0);
|
case _O_INPUT: OPT_NUMBER("--input", dev->input, 0, 128, 0);
|
||||||
@@ -378,7 +400,7 @@ int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t
|
|||||||
|
|
||||||
# ifdef WITH_SETPROCTITLE
|
# ifdef WITH_SETPROCTITLE
|
||||||
if (process_name_prefix != NULL) {
|
if (process_name_prefix != NULL) {
|
||||||
process_set_name_prefix(argc, argv, process_name_prefix);
|
process_set_name_prefix(options->argc, options->argv, process_name_prefix);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|||||||
@@ -27,4 +27,14 @@
|
|||||||
#include "http/server.h"
|
#include "http/server.h"
|
||||||
|
|
||||||
|
|
||||||
int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server);
|
struct options_t {
|
||||||
|
int argc;
|
||||||
|
char **argv;
|
||||||
|
char **argv_copy;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct options_t *options_init(int argc, char *argv[]);
|
||||||
|
void options_destroy(struct options_t *options);
|
||||||
|
|
||||||
|
int options_parse(struct options_t *options, struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server);
|
||||||
|
|||||||
Reference in New Issue
Block a user