Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Permission error while creating lock file
Forum Updated to NodeBB v4.3 + New Features

Permission error while creating lock file

Scheduled Pinned Locked Moved Solved Mobile and Embedded
17 Posts 5 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    angelatyizhong
    wrote on last edited by
    #1

    I creat one app with Qt,i want to open serial ,but failed,the error message is "permission error while creating lock file",why?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      If on Linux, your user that you
      are logged it with might no have access
      else please give a bit details on platform,. Qt version and show some code.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        angelatyizhong
        wrote on last edited by
        #3

        on android4.4.2

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Ok then it might the old issue
          https://forum.qt.io/topic/41857/solved-qserialport-in-qt-5-3-running-in-android/2
          "
          During opening of QtSerialPort tries to create lock-files in directories /var/lock, /etc/locks... /data/local/tmp.
          On linux, some of these directories have the rights for writing from the usual user... so, no problem. But on Android, seems that these directories available only for root user, so, probably this is a problem for your application."

          (kuzulis wrote QSerialPort)

          I though it was fixed / change in newer Qt but seems not.

          1 Reply Last reply
          1
          • A Offline
            A Offline
            angelatyizhong
            wrote on last edited by
            #5

            my qt version is 5.9.the android must be rooted?

            mrjjM 1 Reply Last reply
            0
            • A angelatyizhong

              my qt version is 5.9.the android must be rooted?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @angelatyizhong

              it seems so
              https://bugreports.qt.io/browse/QTBUG-32672

              1 Reply Last reply
              0
              • A Offline
                A Offline
                angelatyizhong
                wrote on last edited by
                #7

                how can i read and write /var ,/etc ,/tmp and others files without root the android.

                jsulmJ 1 Reply Last reply
                0
                • A angelatyizhong

                  how can i read and write /var ,/etc ,/tmp and others files without root the android.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @angelatyizhong said in Permission error while creating lock file:

                  how can i read and write /var ,/etc ,/tmp and others files without root the android

                  You can't write there on Android without rooting the device, that's what @mrjj said.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • A Offline
                    A Offline
                    angelatyizhong
                    wrote on last edited by
                    #9

                    other serial app can work OK without root the android.How should i set the QT app to make it OK without root the android.

                    J.HilkJ 1 Reply Last reply
                    0
                    • A angelatyizhong

                      other serial app can work OK without root the android.How should i set the QT app to make it OK without root the android.

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      @angelatyizhong something has to have root access, if not your application, than a driver, or the driver has to be baked in the OS, highly unlikely for non rooted Android devices.

                      Only alternative is talking via the android USB api to your device. Thats going to take time to write and I'm not convinced it will work correctly in the first place.


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      1
                      • A Offline
                        A Offline
                        angelatyizhong
                        wrote on last edited by
                        #11

                        i find one source code witch can work ok without root the android.can i do with QT like this?how can i do?/
                        /检查访问权限,如果没有读写权限,进行文件操作,修改文件访问权限
                        if (!device.canRead() || !device.canWrite()) {
                        try {
                        //通过挂载到linux的方式,修改文件的操作权限
                        Process su = Runtime.getRuntime().exec("/system/xbin/su");
                        String cmd = "chmod 777 " + device.getAbsolutePath() + "\n" + "exit\n";
                        su.getOutputStream().write(cmd.getBytes());

                                    if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) {
                                        throw new SecurityException();
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    throw new SecurityException();
                                }
                        
                        jsulmJ J.HilkJ 2 Replies Last reply
                        0
                        • A angelatyizhong

                          i find one source code witch can work ok without root the android.can i do with QT like this?how can i do?/
                          /检查访问权限,如果没有读写权限,进行文件操作,修改文件访问权限
                          if (!device.canRead() || !device.canWrite()) {
                          try {
                          //通过挂载到linux的方式,修改文件的操作权限
                          Process su = Runtime.getRuntime().exec("/system/xbin/su");
                          String cmd = "chmod 777 " + device.getAbsolutePath() + "\n" + "exit\n";
                          su.getOutputStream().write(cmd.getBytes());

                                      if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) {
                                          throw new SecurityException();
                                      }
                                  } catch (Exception e) {
                                      e.printStackTrace();
                                      throw new SecurityException();
                                  }
                          
                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @angelatyizhong I really doubt su works on a non-rooted Android. See https://android.stackexchange.com/questions/207623/what-special-privileges-system-xbin-su-does-have-w-r-t-root-access

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • A angelatyizhong

                            i find one source code witch can work ok without root the android.can i do with QT like this?how can i do?/
                            /检查访问权限,如果没有读写权限,进行文件操作,修改文件访问权限
                            if (!device.canRead() || !device.canWrite()) {
                            try {
                            //通过挂载到linux的方式,修改文件的操作权限
                            Process su = Runtime.getRuntime().exec("/system/xbin/su");
                            String cmd = "chmod 777 " + device.getAbsolutePath() + "\n" + "exit\n";
                            su.getOutputStream().write(cmd.getBytes());

                                        if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) {
                                            throw new SecurityException();
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        throw new SecurityException();
                                    }
                            
                            J.HilkJ Offline
                            J.HilkJ Offline
                            J.Hilk
                            Moderators
                            wrote on last edited by
                            #13

                            @angelatyizhong said in Permission error while creating lock file:

                            /system/xbin/su

                            take your time and read this answer, it's very detailed and good
                            https://android.stackexchange.com/a/207902

                            TLDR:
                            Debug only


                            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                            Q: What's that?
                            A: It's blue light.
                            Q: What does it do?
                            A: It turns blue.

                            1 Reply Last reply
                            1
                            • K Offline
                              K Offline
                              kuzulis
                              Qt Champions 2020
                              wrote on last edited by kuzulis
                              #14

                              BTW: QSerialPort officially does not support on Android. You even has not rights to open the device there (without of a root rights). One exception when it is possible - it if yours is an Android BSP developer and provides your Android devices with the pre-configured kernel and other stuff.

                              1 Reply Last reply
                              1
                              • A Offline
                                A Offline
                                angelatyizhong
                                wrote on last edited by
                                #15

                                my android is rooted ,how can i send chmod order?

                                jsulmJ 1 Reply Last reply
                                0
                                • A angelatyizhong

                                  my android is rooted ,how can i send chmod order?

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @angelatyizhong said in Permission error while creating lock file:

                                  how can i send chmod order?

                                  Do you mean from your app? Using QProcess.

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  2
                                  • K Offline
                                    K Offline
                                    kuzulis
                                    Qt Champions 2020
                                    wrote on last edited by kuzulis
                                    #17

                                    It is strange why the lock-file creation fails for you. Because the source code of QSP is the following:

                                        static const QStringList lockDirectoryPaths = QStringList()
                                            << QStringLiteral("/var/lock")
                                            << QStringLiteral("/etc/locks")
                                            << QStringLiteral("/var/spool/locks")
                                            << QStringLiteral("/var/spool/uucp")
                                            << QStringLiteral("/tmp")
                                            << QStringLiteral("/var/tmp")
                                            << QStringLiteral("/var/lock/lockdev")
                                            << QStringLiteral("/run/lock")
                                    #ifdef Q_OS_ANDROID
                                            << QStringLiteral("/data/local/tmp")
                                    #endif
                                            << QStandardPaths::writableLocation(QStandardPaths::TempLocation);
                                    

                                    So, even "/data/local/tmp" or "QStandardPaths::TempLocation" does not work? If so, maybe you need to configure and the Android permissions, using a Manifest file? I meant the permissions to the temporary directories...

                                    Anyway, you can try to find a writable temporary directory himself (just do separate non-QSP related tests), and then I can add your new solution to the QSP.

                                    1 Reply Last reply
                                    2

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved