Trying to create a Directory using system call - not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tvnaidu
    Contributor
    • Oct 2009
    • 365

    Trying to create a Directory using system call - not working

    I am trying to create a directory "/log" in linux in below file, it is not creating, I commented windows call and added linux call ro create /log dir.

    #define DEFAULT_LOG_DIR "/log"

    void main()
    {
    char dirName[64];

    strcpy(dirName, DEFAULT_LOG_DIR );

    //_mkdir(dirName) //this is windows mkdir
    system("mkdir dirName"); //LINUX

    }
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You'll need permissions to do that. See libgksu to authenticate your command.

    Comment

    • tvnaidu
      Contributor
      • Oct 2009
      • 365

      #3
      I have permisson, still not able to create /log dir.

      Comment

      • RRick
        Recognized Expert Contributor
        • Feb 2007
        • 463

        #4
        In linux, the root directory /, is owned and controlled by the root account. You need to be root or have root privileges to create a directory there.

        BTW: Try strace with this executable. It should tell you what is happening during the directory creation.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Your mkdir needs a string:

          "mkdir $/Hello/world/logfile.log"

          You are passing "mkdir dirname". Are you nintending to create a direcory named dirname?

          Comment

          • tvnaidu
            Contributor
            • Oct 2009
            • 365

            #6
            I need to create /log directory which I defined with #define.
            I have root perm.

            Comment

            • RRick
              Recognized Expert Contributor
              • Feb 2007
              • 463

              #7
              What does strace tell you?

              Comment

              Working...