c - File can be opened only by root user..Wrong permisssions given, i guess -


My program basically executes executable files with command line arguments. A hair procedure is a brew and hair process is produced in the file "filename".

The problem is that the file has been created and the data is written but it can only be opened by the root user. Who can make this program a user readable ?

The code is: -

  #include & lt; Stdio.h & gt; #to & lt include, string.h & gt; // strcpy () #includes & lt; Malloc.h & gt; // Molok () #includes & lt; Unistd.h & gt; // Use of fork () is included & lt; Stdlib.h & gt; Use the // exit () function to include & lt; Sys / wait.h & gt; // waitpad () # include & lt; Fcntl.h & gt; Int main (int argc, char ** argv) {char * command; Four input [256]; Char ** args = NULL; Char * arg; Int count = 0; Char * binary; Pid_t pid; Int fdw; Printf ("Enter the name of executable (with full path)"); Fgets (input, 256, stdin); Command = maulock (input); Strncpy (command, input, strlen (input) -1); Binary = strotok (command, ""); Arg = malloc (sizeof (four *)); Args [0] = malloc (strlen (binary) +1); Strcpy (args [0], binary); Args = realloc (args, sizeof (char *) * 10); count ++ args [count] = (if (= arg = strtok (NULL, "") = =) (if calculation% 10 == 0) Malloc (strlen (arg)); strcpy (args [count], arg);} arg = [calculate] = null; if ((fdw = open ("filename", o_wronly | O_EXCL | O_CREAT | 0700)) == -1) membrane ("error in file creation"); pass (1); dup (FDW); if ((pid = fork ()) == -1) {perror ("fault error ... ... \ N "); Exit (1);} If (pid == 0) execvp (args [0], & args [0]); Else {int position; waiting speed (-1, and position, 0) ;} Return 0;}  

Read the manpad again for open Defense, you're not file mode logic causes correctly and flags disturbances in the process.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -