Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
6a7c4947
Commit
6a7c4947
authored
Oct 05, 2021
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
server: Avoid using getopt_long().
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
5f921c7f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
140 additions
and
52 deletions
+140
-52
main.c
server/main.c
+140
-52
No files found.
server/main.c
View file @
6a7c4947
...
@@ -28,9 +28,6 @@
...
@@ -28,9 +28,6 @@
#include <stdlib.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/time.h>
#include <unistd.h>
#include <unistd.h>
#ifdef HAVE_GETOPT_H
# include <getopt.h>
#endif
#include "object.h"
#include "object.h"
#include "file.h"
#include "file.h"
...
@@ -60,64 +57,154 @@ static void usage( FILE *fh )
...
@@ -60,64 +57,154 @@ static void usage( FILE *fh )
fprintf
(
fh
,
"
\n
"
);
fprintf
(
fh
,
"
\n
"
);
}
}
static
void
parse_args
(
int
argc
,
char
*
argv
[]
)
static
void
option_callback
(
int
optc
,
char
*
optarg
)
{
{
int
ret
,
optc
;
int
ret
;
s
tatic
struct
option
long_options
[]
=
s
witch
(
optc
)
{
{
{
"debug"
,
2
,
NULL
,
'd'
},
case
'd'
:
{
"foreground"
,
0
,
NULL
,
'f'
},
if
(
optarg
&&
isdigit
(
*
optarg
))
{
"help"
,
0
,
NULL
,
'h'
},
debug_level
=
atoi
(
optarg
);
{
"kill"
,
2
,
NULL
,
'k'
},
else
{
"persistent"
,
2
,
NULL
,
'p'
},
debug_level
++
;
{
"version"
,
0
,
NULL
,
'v'
},
break
;
{
"wait"
,
0
,
NULL
,
'w'
},
case
'f'
:
{
NULL
,
0
,
NULL
,
0
}
foreground
=
1
;
};
break
;
case
'h'
:
usage
(
stdout
);
exit
(
0
);
break
;
case
'k'
:
if
(
optarg
&&
isdigit
(
*
optarg
))
ret
=
kill_lock_owner
(
atoi
(
optarg
)
);
else
ret
=
kill_lock_owner
(
-
1
);
exit
(
!
ret
);
case
'p'
:
if
(
optarg
&&
isdigit
(
*
optarg
))
master_socket_timeout
=
(
timeout_t
)
atoi
(
optarg
)
*
-
TICKS_PER_SEC
;
else
master_socket_timeout
=
TIMEOUT_INFINITE
;
break
;
case
'v'
:
fprintf
(
stderr
,
"%s
\n
"
,
PACKAGE_STRING
);
exit
(
0
);
case
'w'
:
wait_for_lock
();
exit
(
0
);
}
}
server_argv0
=
argv
[
0
];
/* command-line option parsing */
/* partly based on the GLibc getopt() implementation */
static
struct
long_option
{
const
char
*
name
;
int
has_arg
;
int
val
;
}
long_options
[]
=
{
{
"debug"
,
2
,
'd'
},
{
"foreground"
,
0
,
'f'
},
{
"help"
,
0
,
'h'
},
{
"kill"
,
2
,
'k'
},
{
"persistent"
,
2
,
'p'
},
{
"version"
,
0
,
'v'
},
{
"wait"
,
0
,
'w'
},
{
NULL
}
};
while
((
optc
=
getopt_long
(
argc
,
argv
,
"d::fhk::p::vw"
,
long_options
,
NULL
))
!=
-
1
)
static
void
parse_options
(
int
argc
,
char
**
argv
,
const
char
*
short_opts
,
const
struct
long_option
*
long_opts
,
void
(
*
callback
)(
int
,
char
*
)
)
{
const
char
*
flag
;
char
*
start
,
*
end
;
int
i
;
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
{
switch
(
optc
)
if
(
argv
[
i
][
0
]
!=
'-'
||
!
argv
[
i
][
1
])
/* not an option */
continue
;
if
(
!
strcmp
(
argv
[
i
],
"--"
))
break
;
start
=
argv
[
i
]
+
1
+
(
argv
[
i
][
1
]
==
'-'
);
if
(
argv
[
i
][
1
]
==
'-'
)
{
{
case
'd'
:
/* handle long option */
if
(
optarg
&&
isdigit
(
*
optarg
))
const
struct
long_option
*
opt
,
*
found
=
NULL
;
debug_level
=
atoi
(
optarg
);
int
count
=
0
;
else
debug_level
++
;
if
(
!
(
end
=
strchr
(
start
,
'='
)))
end
=
start
+
strlen
(
start
);
break
;
for
(
opt
=
long_opts
;
opt
&&
opt
->
name
;
opt
++
)
case
'f'
:
{
foreground
=
1
;
if
(
strncmp
(
opt
->
name
,
start
,
end
-
start
))
continue
;
break
;
if
(
!
opt
->
name
[
end
-
start
])
/* exact match */
case
'h'
:
{
usage
(
stdout
);
found
=
opt
;
exit
(
0
);
count
=
1
;
break
;
break
;
case
'k'
:
}
if
(
optarg
&&
isdigit
(
*
optarg
))
if
(
!
found
)
ret
=
kill_lock_owner
(
atoi
(
optarg
)
);
{
else
found
=
opt
;
ret
=
kill_lock_owner
(
-
1
);
count
++
;
exit
(
!
ret
);
}
case
'p'
:
else
if
(
found
->
has_arg
!=
opt
->
has_arg
||
found
->
val
!=
opt
->
val
)
if
(
optarg
&&
isdigit
(
*
optarg
))
{
master_socket_timeout
=
(
timeout_t
)
atoi
(
optarg
)
*
-
TICKS_PER_SEC
;
count
++
;
else
}
master_socket_timeout
=
TIMEOUT_INFINITE
;
}
if
(
count
>
1
)
goto
error
;
if
(
found
)
{
if
(
*
end
)
{
if
(
!
found
->
has_arg
)
goto
error
;
end
++
;
/* skip '=' */
}
else
if
(
found
->
has_arg
==
1
)
{
if
(
i
==
argc
-
1
)
goto
error
;
end
=
argv
[
++
i
];
}
else
end
=
NULL
;
callback
(
found
->
val
,
end
);
continue
;
}
goto
error
;
}
/* handle short option */
for
(
;
*
start
;
start
++
)
{
if
(
!
(
flag
=
strchr
(
short_opts
,
*
start
)))
goto
error
;
if
(
flag
[
1
]
==
':'
)
{
end
=
start
+
1
;
if
(
!*
end
)
end
=
NULL
;
if
(
flag
[
2
]
!=
':'
&&
!
end
)
{
if
(
i
==
argc
-
1
)
goto
error
;
end
=
argv
[
++
i
];
}
callback
(
*
start
,
end
);
break
;
break
;
case
'v'
:
}
fprintf
(
stderr
,
"%s
\n
"
,
PACKAGE_STRING
);
callback
(
*
start
,
NULL
);
exit
(
0
);
case
'w'
:
wait_for_lock
();
exit
(
0
);
default:
usage
(
stderr
);
exit
(
1
);
}
}
}
}
return
;
error:
usage
(
stderr
);
exit
(
1
);
}
}
static
void
sigterm_handler
(
int
signum
)
static
void
sigterm_handler
(
int
signum
)
...
@@ -128,7 +215,8 @@ static void sigterm_handler( int signum )
...
@@ -128,7 +215,8 @@ static void sigterm_handler( int signum )
int
main
(
int
argc
,
char
*
argv
[]
)
int
main
(
int
argc
,
char
*
argv
[]
)
{
{
setvbuf
(
stderr
,
NULL
,
_IOLBF
,
0
);
setvbuf
(
stderr
,
NULL
,
_IOLBF
,
0
);
parse_args
(
argc
,
argv
);
server_argv0
=
argv
[
0
];
parse_options
(
argc
,
argv
,
"d::fhk::p::vw"
,
long_options
,
option_callback
);
/* setup temporary handlers before the real signal initialization is done */
/* setup temporary handlers before the real signal initialization is done */
signal
(
SIGPIPE
,
SIG_IGN
);
signal
(
SIGPIPE
,
SIG_IGN
);
...
...
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