Reply
Thread Tools
Posts: 270 | Thanked: 239 times | Joined on Dec 2009 @ Czech Republic
#11
I changed target to /home/user/.app set write access and app still crash.
 
spanner's Avatar
Posts: 253 | Thanked: 184 times | Joined on Nov 2009 @ Bristol, UK
#12
Originally Posted by Figa View Post
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).
 

The Following User Says Thank You to spanner For This Useful Post:
Posts: 270 | Thanked: 239 times | Joined on Dec 2009 @ Czech Republic
#13
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);

}

Last edited by Figa; 2010-03-01 at 19:48.
 
spanner's Avatar
Posts: 253 | Thanked: 184 times | Joined on Nov 2009 @ Bristol, UK
#14
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
 
Posts: 270 | Thanked: 239 times | Joined on Dec 2009 @ Czech Republic
#15
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's Avatar
Posts: 253 | Thanked: 184 times | Joined on Nov 2009 @ Bristol, UK
#16
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.
 

The Following User Says Thank You to spanner For This Useful Post:
Posts: 270 | Thanked: 239 times | Joined on Dec 2009 @ Czech Republic
#17
Thank you very much. Now it works. I have a last question. How run this command after install app?
 
spanner's Avatar
Posts: 253 | Thanked: 184 times | Joined on Nov 2009 @ Bristol, UK
#18
Originally Posted by Figa View Post
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.
 
Posts: 270 | Thanked: 239 times | Joined on Dec 2009 @ Czech Republic
#19
Thanks but before first run this program is this dir created. Dir creates in installation of app.
 
Posts: 5,335 | Thanked: 8,187 times | Joined on Mar 2007 @ Pennsylvania, USA
#20
Originally Posted by Figa View Post
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.
__________________
maemo.org profile
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 18:08.