Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
bda16d36
Commit
bda16d36
authored
Sep 09, 2014
by
Vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Daemonize options
parent
0c031461
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
1 deletion
+55
-1
main.c
main.c
+55
-1
No files found.
main.c
View file @
bda16d36
...
...
@@ -403,6 +403,8 @@ void usage (void) {
printf
(
" -W send dialog_list query and wait for answer before reading input
\n
"
);
printf
(
" -C disable color output
\n
"
);
printf
(
" -R disable readline
\n
"
);
printf
(
" -d daemon mode
\n
"
);
printf
(
" -L <log-name> log file name
\n
"
);
exit
(
1
);
}
...
...
@@ -410,6 +412,9 @@ void usage (void) {
//extern char *rsa_public_key_name;
//extern int default_dc_num;
char
*
log_net_file
;
FILE
*
log_net_f
;
...
...
@@ -417,10 +422,47 @@ int register_mode;
int
disable_auto_accept
;
int
wait_dialog_list
;
char
*
logname
;
int
daemonize
;
void
reopen_logs
(
void
)
{
int
fd
;
fflush
(
stdout
);
fflush
(
stderr
);
if
((
fd
=
open
(
"/dev/null"
,
O_RDWR
,
0
))
!=
-
1
)
{
dup2
(
fd
,
0
);
dup2
(
fd
,
1
);
dup2
(
fd
,
2
);
if
(
fd
>
2
)
{
close
(
fd
);
}
}
if
(
logname
&&
(
fd
=
open
(
logname
,
O_WRONLY
|
O_APPEND
|
O_CREAT
,
0640
))
!=
-
1
)
{
dup2
(
fd
,
1
);
dup2
(
fd
,
2
);
if
(
fd
>
2
)
{
close
(
fd
);
}
}
}
static
void
sigusr1_handler
(
const
int
sig
)
{
fprintf
(
stderr
,
"got SIGUSR1, rotate logs.
\n
"
);
reopen_logs
();
signal
(
SIGUSR1
,
sigusr1_handler
);
}
static
void
sighup_handler
(
const
int
sig
)
{
fprintf
(
stderr
,
"got SIGHUP.
\n
"
);
signal
(
SIGHUP
,
sighup_handler
);
}
void
args_parse
(
int
argc
,
char
**
argv
)
{
int
opt
=
0
;
while
((
opt
=
getopt
(
argc
,
argv
,
"u:hk:vNl:fEwWCR"
while
((
opt
=
getopt
(
argc
,
argv
,
"u:hk:vNl:fEwWCR
dL:
"
#ifdef HAVE_LIBCONFIG
"c:p:"
#else
...
...
@@ -485,6 +527,12 @@ void args_parse (int argc, char **argv) {
case
'R'
:
readline_disabled
++
;
break
;
case
'd'
:
daemonize
++
;
break
;
case
'L'
:
logname
=
optarg
;
break
;
case
'h'
:
default:
usage
();
...
...
@@ -532,6 +580,12 @@ int main (int argc, char **argv) {
log_level
=
10
;
args_parse
(
argc
,
argv
);
if
(
daemonize
)
{
signal
(
SIGHUP
,
sighup_handler
);
signal
(
SIGUSR1
,
sigusr1_handler
);
reopen_logs
();
}
printf
(
"Telegram-cli version "
TGL_VERSION
", Copyright (C) 2013-2014 Vitaly Valtman
\n
"
"Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.
\n
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment