Commit 908086b0 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk Committed by Alessandro Rubini

tools: detect when user runs without superuser rights and inform him instead of segfault

parent d69145e6
...@@ -52,8 +52,8 @@ int main(int argc, char **argv) ...@@ -52,8 +52,8 @@ int main(int argc, char **argv)
if(!card) if(!card)
{ {
fprintf(stderr, "%s: Can't detect a SPEC card under the given " fprintf(stderr, "%s: Can't detect a SPEC card under the given "
"adress.\nMake sure a SPEC card is present in your PC " "adress.\nMake sure a SPEC card is present in your PC, "
"and the driver is loaded.\n", argv[0]); "the driver is loaded and you run the program as root.\n", argv[0]);
exit(1); exit(1);
} }
......
...@@ -43,8 +43,8 @@ int main(int argc, char **argv) ...@@ -43,8 +43,8 @@ int main(int argc, char **argv)
if(!card) if(!card)
{ {
fprintf(stderr, "Can't detect a SPEC card under the given " fprintf(stderr, "Can't detect a SPEC card under the given "
"adress. Make sure a SPEC card is present in your PC " "adress.\nMake sure a SPEC card is present in your PC, "
"and the driver is loaded.\n"); "the driver is loaded and you run the program as root.\n");
exit(1); exit(1);
} }
......
...@@ -122,8 +122,8 @@ int main(int argc, char **argv) ...@@ -122,8 +122,8 @@ int main(int argc, char **argv)
if(!card) if(!card)
{ {
fprintf(stderr, "Can't detect a SPEC card under the given " fprintf(stderr, "Can't detect a SPEC card under the given "
"adress. Make sure a SPEC card is present in your PC " "adress.\nMake sure a SPEC card is present in your PC, "
"and the driver is loaded.\n"); "the driver is loaded and you run the program as root.\n");
exit(1); exit(1);
} }
......
...@@ -104,6 +104,12 @@ void *spec_open(int bus, int dev) ...@@ -104,6 +104,12 @@ void *spec_open(int bus, int dev)
card->bar0 = spec_map_area(bus, dev, BASE_BAR0, 0x100000); card->bar0 = spec_map_area(bus, dev, BASE_BAR0, 0x100000);
card->bar4 = spec_map_area(bus, dev, BASE_BAR4, 0x1000); card->bar4 = spec_map_area(bus, dev, BASE_BAR4, 0x1000);
if(!card->bar0 && !card->bar4)
{
free(card);
card = NULL;
}
return card; return card;
} }
......
...@@ -78,8 +78,8 @@ int main(int argc, char **argv) ...@@ -78,8 +78,8 @@ int main(int argc, char **argv)
if(!card) if(!card)
{ {
fprintf(stderr, "Can't detect a SPEC card under the given " fprintf(stderr, "Can't detect a SPEC card under the given "
"adress. Make sure a SPEC card is present in your PC " "adress. Make sure a SPEC card is present in your PC, "
"and the driver is loaded.\n"); "the driver is loaded and you run the program as root.\n");
exit(1); exit(1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment