diff options
author | Joe Crayne <joe@jerkface.net> | 2019-10-12 22:41:01 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-10-12 22:41:01 -0400 |
commit | cdf1abf190f1097c4f6ae2ff0a9fa023df6982f1 (patch) | |
tree | 448e7823c18110750823a4bdd599af336983a314 /chpst.c | |
parent | 695f7bb74e51cba61f3e1c035dd47ae68ac2964c (diff) |
Applied debian patch to fix compiler warnings.
0014-fix-implicit-declarations-incompatible-types-argv-ty.patch
From: Jan <cloux@rote.ch>
Date: Sat, 2 Mar 2019 15:41:59 +0100
Subject: fix: implicit declarations, incompatible types, argv type
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Fixed a few compiler warnings:
prot.c:13:7: warning: implicit declaration of function ‘setgroups’ [-Wimplicit-function-declaration]
chpst.c:80:7: warning: implicit declaration of function ‘setgroups’; did you mean ‘getgroups’? [-Wimplicit-function-declaration]
- added #include <grp.h>, see: https://linux.die.net/man/2/setgroups
chkshsgr.c:11:19: warning: passing argument 2 of ‘getgroups’ from incompatible pointer type [-Wincompatible-pointer-types]
- change 'short' to 'gid_t', see: https://linux.die.net/man/2/setgroups
pathexec_run.c:18:5: warning: implicit declaration of function ‘execve’ [-Wimplicit-function-declaration]
- add #include <unistd.h>, see: http://man7.org/linux/man-pages/man2/execve.2.html
prot.c:17:10: warning: implicit declaration of function ‘setgid’; did you mean ‘getgrgid’? [-Wimplicit-function-declaration]
- add #include <unistd.h>, see: https://linux.die.net/man/3/setgid
seek_set.c:9:7: warning: implicit declaration of function ‘lseek’ [-Wimplicit-function-declaration]
- add #include <unistd.h>, see: https://linux.die.net/man/2/lseek
--------------------------------------
Fixed type of argv, from 'const char **argv' to 'char **argv'
This resolves a lot of compiler typecast warnings like:
pathexec_run.c:19:17: warning: passing argument 2 of ‘execve’ from incompatible pointer type [-Wincompatible-pointer-types]
NOTE: this change might be disputable and not obvious at first.
For arguments for argv as 'char **argv', see:
The C Programming Language, Kernighan & Ritchie, Second Edition, Section 5.10, page 110
Command-line Arguments: main(int argc, char *argv[])
From https://riptutorial.com/c/example/3675/original--hello--world---in-k-r-c
int main(int argc, char **argv)
From C/C++ Kompendium (DE), Markt+Technik Verlag 2000, page 576, Chapter 12, main() Parameter:
int main(int argc, char *argv[])
From http://www.cplusplus.com/articles/DEN36Up4/
int main(int argc, char* argv[]) // or char** argv
From https://ece.uwaterloo.ca/~dwharder/icsrts/C/05/
int main( int argc, char *argv[] )
At
https://stackoverflow.com/questions/5808679/why-is-main-argument-argv-of-type-char-rather-than-const-char
is argued, that:
- argv isn't const, since it's being created at runtime
- in certain cases you should be able to rewrite argv from you program
The main argument for this type change:
the argv is used in a call to execve, so the type should be declared as compatible
with execve parameters. http://man7.org/linux/man-pages/man2/execve.2.html
defines:
int execve(const char *filename, char *const argv[], char *const envp[]);
so every argv defined as 'const char *const argv[]' was changed to:
'char *const argv[]'
Diffstat (limited to 'chpst.c')
-rw-r--r-- | chpst.c | 31 |
1 files changed, 16 insertions, 15 deletions
@@ -3,6 +3,7 @@ | |||
3 | #include <sys/time.h> | 3 | #include <sys/time.h> |
4 | #include <sys/resource.h> | 4 | #include <sys/resource.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | #include <grp.h> | ||
6 | #include "sgetopt.h" | 7 | #include "sgetopt.h" |
7 | #include "error.h" | 8 | #include "error.h" |
8 | #include "strerr.h" | 9 | #include "strerr.h" |
@@ -40,7 +41,7 @@ void usage() { strerr_die4x(100, "usage: ", progname, USAGE_MAIN, "\n"); } | |||
40 | 41 | ||
41 | char *set_user =0; | 42 | char *set_user =0; |
42 | char *env_user =0; | 43 | char *env_user =0; |
43 | const char *argv0 =0; | 44 | char *argv0 =0; |
44 | const char *env_dir =0; | 45 | const char *env_dir =0; |
45 | unsigned int verbose =0; | 46 | unsigned int verbose =0; |
46 | unsigned int pgrp =0; | 47 | unsigned int pgrp =0; |
@@ -258,14 +259,14 @@ void slimit() { | |||
258 | } | 259 | } |
259 | 260 | ||
260 | /* argv[0] */ | 261 | /* argv[0] */ |
261 | void setuidgid(int, const char *const *); | 262 | void setuidgid(int, char *const *); |
262 | void envuidgid(int, const char *const *); | 263 | void envuidgid(int, char *const *); |
263 | void envdir(int, const char *const *); | 264 | void envdir(int, char *const *); |
264 | void pgrphack(int, const char *const *); | 265 | void pgrphack(int, char *const *); |
265 | void setlock(int, const char *const *); | 266 | void setlock(int, char *const *); |
266 | void softlimit(int, const char *const *); | 267 | void softlimit(int, char *const *); |
267 | 268 | ||
268 | int main(int argc, const char **argv) { | 269 | int main(int argc, char **argv) { |
269 | int opt; | 270 | int opt; |
270 | int i; | 271 | int i; |
271 | unsigned long ul; | 272 | unsigned long ul; |
@@ -366,7 +367,7 @@ int main(int argc, const char **argv) { | |||
366 | void setuidgid_usage() { | 367 | void setuidgid_usage() { |
367 | strerr_die4x(100, "usage: ", progname, USAGE_SETUIDGID, "\n"); | 368 | strerr_die4x(100, "usage: ", progname, USAGE_SETUIDGID, "\n"); |
368 | } | 369 | } |
369 | void setuidgid(int argc, const char *const *argv) { | 370 | void setuidgid(int argc, char *const *argv) { |
370 | const char *account; | 371 | const char *account; |
371 | 372 | ||
372 | if (! (account =*++argv)) setuidgid_usage(); | 373 | if (! (account =*++argv)) setuidgid_usage(); |
@@ -379,7 +380,7 @@ void setuidgid(int argc, const char *const *argv) { | |||
379 | void envuidgid_usage() { | 380 | void envuidgid_usage() { |
380 | strerr_die4x(100, "usage: ", progname, USAGE_ENVUIDGID, "\n"); | 381 | strerr_die4x(100, "usage: ", progname, USAGE_ENVUIDGID, "\n"); |
381 | } | 382 | } |
382 | void envuidgid(int argc, const char *const *argv) { | 383 | void envuidgid(int argc, char *const *argv) { |
383 | const char *account; | 384 | const char *account; |
384 | 385 | ||
385 | if (! (account =*++argv)) envuidgid_usage(); | 386 | if (! (account =*++argv)) envuidgid_usage(); |
@@ -392,7 +393,7 @@ void envuidgid(int argc, const char *const *argv) { | |||
392 | void envdir_usage() { | 393 | void envdir_usage() { |
393 | strerr_die4x(100, "usage: ", progname, USAGE_ENVDIR, "\n"); | 394 | strerr_die4x(100, "usage: ", progname, USAGE_ENVDIR, "\n"); |
394 | } | 395 | } |
395 | void envdir(int argc, const char *const *argv) { | 396 | void envdir(int argc, char *const *argv) { |
396 | const char *dir; | 397 | const char *dir; |
397 | 398 | ||
398 | if (! (dir =*++argv)) envdir_usage(); | 399 | if (! (dir =*++argv)) envdir_usage(); |
@@ -405,7 +406,7 @@ void envdir(int argc, const char *const *argv) { | |||
405 | void pgrphack_usage() { | 406 | void pgrphack_usage() { |
406 | strerr_die4x(100, "usage: ", progname, USAGE_PGRPHACK, "\n"); | 407 | strerr_die4x(100, "usage: ", progname, USAGE_PGRPHACK, "\n"); |
407 | } | 408 | } |
408 | void pgrphack(int argc, const char *const *argv) { | 409 | void pgrphack(int argc, char *const *argv) { |
409 | if (! *++argv) pgrphack_usage(); | 410 | if (! *++argv) pgrphack_usage(); |
410 | setsid(); | 411 | setsid(); |
411 | pathexec(argv); | 412 | pathexec(argv); |
@@ -415,7 +416,7 @@ void pgrphack(int argc, const char *const *argv) { | |||
415 | void setlock_usage() { | 416 | void setlock_usage() { |
416 | strerr_die4x(100, "usage: ", progname, USAGE_SETLOCK, "\n"); | 417 | strerr_die4x(100, "usage: ", progname, USAGE_SETLOCK, "\n"); |
417 | } | 418 | } |
418 | void setlock(int argc, const char *const *argv) { | 419 | void setlock(int argc, char *const *argv) { |
419 | int opt; | 420 | int opt; |
420 | unsigned int delay =0; | 421 | unsigned int delay =0; |
421 | unsigned int x =0; | 422 | unsigned int x =0; |
@@ -449,7 +450,7 @@ void getlarg(long *l) { | |||
449 | if (optarg[scan_ulong(optarg, &ul)]) usage(); | 450 | if (optarg[scan_ulong(optarg, &ul)]) usage(); |
450 | *l =ul; | 451 | *l =ul; |
451 | } | 452 | } |
452 | void softlimit(int argc, const char *const *argv) { | 453 | void softlimit(int argc, char *const *argv) { |
453 | int opt; | 454 | int opt; |
454 | 455 | ||
455 | while ((opt =getopt(argc,argv,"a:c:d:f:l:m:o:p:r:s:t:")) != opteof) | 456 | while ((opt =getopt(argc,argv,"a:c:d:f:l:m:o:p:r:s:t:")) != opteof) |