maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Wierd Crash (https://talk.maemo.org/showthread.php?t=46200)

Figa 2010-03-01 19:14

Re: Wierd Crash
 
I changed target to /home/user/.app set write access and app still crash.

spanner 2010-03-01 19:29

Re: Wierd Crash
 
Quote:

Originally Posted by Figa (Post 551443)
I changed target to /home/user/.app set write acces and app still crash.

Come on man, help us to help you.

1) make sure that the directory exists. have your program create it if not.
2) show me
Code:

ls -l -R /home/user/.app
and
Code:

ls -l -d /home/user/.app
3) do some error checking before you use null file handles & complain that your app crashed. e.g.

Code:

#include <stdio.h>
int main()
{
  FILE *file = fopen("/home/user/.app/save.txt","w");
  if (!file) {
    perror("open failed");
    return 1;
  }
}

4) When posting bits of code, show us a minimal program that we can compile ourselves (like I just did).

Figa 2010-03-01 19:46

Re: Wierd Crash
 
Outputs are same... When I am logged as root and use chown a get this error unkown user/group user:user
My code:
Code:

void save() {
        FILE *file = fopen("/home/user/.app/save.txt","w");
        for (int x = 0; x < 9; x++) {
                for (int y = 0; y < 9; y++) {
                        fprintf(file,"%c",unsolved[x][y]);
                }
        }
        for (int x = 0; x < 9; x++) {
                for (int y = 0; y < 9; y++) {
                        fprintf(file,"%c",base[x][y]);
                }
        }
        fclose(file);
        FILE *file2 = fopen("/home/user/.app/candidates.txt","w");
        //save candidates
        char buffer[11];
        string str;
        for (int x = 0; x < 9; x++) {
                for (int y = 0; y < 9; y++) {
                        str = candidates[x][y]+';';
                        strcpy(buffer,str.c_str());
                        fprintf(file2,"%s",buffer);
                }
        }
        fclose(file2);

}


spanner 2010-03-01 19:55

Re: Wierd Crash
 
1) Put the error checking code I showed you after the fopen. That way, if it fails you will know why.

2) You need to run the chown command as root

Figa 2010-03-01 20:01

Re: Wierd Crash
 
1)I know why it cant open file for write.
2) sudo gainroot
chown -R user.user /home/user/.app
unkown user/group user:user

Thank you for your help.

spanner 2010-03-01 20:17

Re: Wierd Crash
 
OK, my mistake: it's
Code:

chown -R user.users /home/user/.app
I am used to systems where user name == group name for "real" users, so I missed the final 's'. Hope this helps.

Figa 2010-03-01 20:32

Re: Wierd Crash
 
Thank you very much. Now it works. I have a last question. How run this command after install app?

spanner 2010-03-01 20:57

Re: Wierd Crash
 
Quote:

Originally Posted by Figa (Post 551546)
Thank you very much. Now it works. I have a last question. How run this command after install app?

You won't have to, if you make the program create this directory itself.

e.g.:
Code:

mkdir("/home/user/.app", 0777);
This way, if you run the program as user, the directory will have the correct ownership automatically.

Figa 2010-03-01 21:09

Re: Wierd Crash
 
Thanks but before first run this program is this dir created. Dir creates in installation of app.

sjgadsby 2010-03-01 21:20

Re: Wierd Crash
 
Quote:

Originally Posted by Figa (Post 551592)
Thanks but before first run this program is this dir created. Dir creates in installation of app.

Creating the directory from within your application allows it to recover and continue working after a user deletes your directory manually (intentionally or otherwise). Relying upon a script that's run during installation will force users to uninstall and reinstall your application to get it working again. That's a bit less friendly.


All times are GMT. The time now is 15:57.

vBulletin® Version 3.8.8