c - Why this program with execl breaks if not run with sudo? -
this diner_info program:
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { printf("diners: %s\n", argv[1]); printf("juice: %s\n", getenv("juice")); return 0; }
and compiled file called diner_info
and here program:
#include <stdlib.h> #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]){ char *my_env[] = {"juice=peach , apple", null}; execle("diner_info", "diner_info", "4", null, my_env); }
when run program this:
korays-mbp:hello2 koraytugay$ sudo ./a.out diners: 4
no problem...
but when do not include sudo getting segmentation fault. why?
operating system os x.
it shouldn't, , made mistake first binary. tested on mac , on ubuntu 14.04 box, , both base runs fine:
brenohl@sid:/tmp$ ./a.out diners: 4 juice: peach , apple brenohl@sid:/tmp$ cat diner.c #include <stdlib.h> #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]){ char *my_env[] = {"juice=peach , apple", null}; execle("diner_info", "diner_info", "4", null, my_env); } brenohl@sid:/tmp$ cat diner_info.c #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { printf("diners: %s\n", argv[1]); printf("juice: %s\n", getenv("juice")); return 0; }
Comments
Post a Comment