• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C Missing Files/Executables In Bash (Launched via C)

olivercox

New Coder
Hi there! Thanks in advance for the help!

I'm encountering an issue in which a shell launched via my C IDE (Gnome Builder) cannot access particular files, leading to issues because it cannot see an executable I need. See a previous post (unsolved) on StackOverflow: How do I launch SBCL (or arbitrary commands) using popen?

Here's the deal:
1. I wish to build a GUI in Gnome Builder, and use it to launch various actions in the backend. The backend is written in Lisp, and for testing purposes I wish to launch the Lisp interpreter (SBCL) with the desired program.
2. When I do so, Gnome Builder throws a "command not found" error for sbcl.
3. If I change the Builder code instead to launch sh, and if I navigate to /usr/bin/ (where sbcl is found) it is not there, along with several other files, e.g. su, vi, etc.
4. sh in the Builder environment appears to have access to my main system (not a virtual machine), because it can see my home directory.

Any ideas?

See system information and code below:

My code:

Code:
int outputter(void){
  FILE *output;
  char buffer[BUFFER];

  output = popen("sbcl", "r");
  if (output == NULL) {
    fputs("POPEN: Failed.\n", stderr);
  }
      else {
        int count = 0;
        while(fgets(buffer, BUFFER-1, output) != NULL) {
            printf("OUTPUT[%d]: %s", count, buffer);
            count ++;
  }
      }
                pclose(output);

  return 0;
}


Sample output of "ls" when run from a normal terminal (see sbcl (sbcl-2 is a link I created as a test)):



rz samba-regedit sancov sane-find-scanner sanstats satyr sb sbcl sbcl-2 scalar scanimage sccmap

And from the shell when run by C in Gnome Builder (OUTPUT[] is an artifact of my program):

OUTPUT[837]: run-with-aspell OUTPUT[838]: saslauthd OUTPUT[839]: sasldblistusers2 OUTPUT[840]: saslpasswd2 OUTPUT[841]: scalar OUTPUT[842]: sclient OUTPUT[843]: scmp_sys_resolver OUTPUT[844]: scp OUTPUT[845]: script OUTPUT[846]: scriptlive OUTPUT[847]: scriptreplay OUTPUT[848]: sdiff OUTPUT[849]: sdl2-config OUTPUT[850]: secret-tool OUTPUT[851]: sed OUTPUT[852]: sefcontext_compile OUTPUT[853]: selabel_digest OUTPUT[854]: selabel_get_digests_all_partial_matches OUTPUT[855]: selabel_lookup OUTPUT[856]: selabel_lookup_best_match OUTPUT[857]: selabel_partial_match OUTPUT[858]: selinux_check_access OUTPUT[859]: selinux_check_securetty_context OUTPUT[860]: selinuxenabled OUTPUT[861]: selinuxexeccon OUTPUT[862]: sepdebugcrcfix OUTPUT[863]: sepol_check_access OUTPUT[864]: sepol_compute_av OUTPUT[865]: sepol_compute_member OUTPUT[866]: sepol_compute_relabel OUTPUT[867]: sepol_validate_transition OUTPUT[868]: seq


System information:
  • OS: Fedora 38
  • Language: C
  • IDE: Gnome Builder
  • sh: GNU bash, version 5.2.15 release (x86_64-redhat-linux-gnu)
 
Hi there! Thanks in advance for the help!

I'm encountering an issue in which a shell launched via my C IDE (Gnome Builder) cannot access particular files, leading to issues because it cannot see an executable I need. See a previous post (unsolved) on StackOverflow: How do I launch SBCL (or arbitrary commands) using popen?

Here's the deal:
1. I wish to build a GUI in Gnome Builder, and use it to launch various actions in the backend. The backend is written in Lisp, and for testing purposes I wish to launch the Lisp interpreter (SBCL) with the desired program.
2. When I do so, Gnome Builder throws a "command not found" error for sbcl.
3. If I change the Builder code instead to launch sh, and if I navigate to /usr/bin/ (where sbcl is found) it is not there, along with several other files, e.g. su, vi, etc.
4. sh in the Builder environment appears to have access to my main system (not a virtual machine), because it can see my home directory.

Any ideas?

See system information and code below:

My code:

Code:
int outputter(void){
  FILE *output;
  char buffer[BUFFER];

  output = popen("sbcl", "r");
  if (output == NULL) {
    fputs("POPEN: Failed.\n", stderr);
  }
      else {
        int count = 0;
        while(fgets(buffer, BUFFER-1, output) != NULL) {
            printf("OUTPUT[%d]: %s", count, buffer);
            count ++;
  }
      }
                pclose(output);

  return 0;
}


Sample output of "ls" when run from a normal terminal (see sbcl (sbcl-2 is a link I created as a test)):



rz samba-regedit sancov sane-find-scanner sanstats satyr sb sbcl sbcl-2 scalar scanimage sccmap

And from the shell when run by C in Gnome Builder (OUTPUT[] is an artifact of my program):

OUTPUT[837]: run-with-aspell OUTPUT[838]: saslauthd OUTPUT[839]: sasldblistusers2 OUTPUT[840]: saslpasswd2 OUTPUT[841]: scalar OUTPUT[842]: sclient OUTPUT[843]: scmp_sys_resolver OUTPUT[844]: scp OUTPUT[845]: script OUTPUT[846]: scriptlive OUTPUT[847]: scriptreplay OUTPUT[848]: sdiff OUTPUT[849]: sdl2-config OUTPUT[850]: secret-tool OUTPUT[851]: sed OUTPUT[852]: sefcontext_compile OUTPUT[853]: selabel_digest OUTPUT[854]: selabel_get_digests_all_partial_matches OUTPUT[855]: selabel_lookup OUTPUT[856]: selabel_lookup_best_match OUTPUT[857]: selabel_partial_match OUTPUT[858]: selinux_check_access OUTPUT[859]: selinux_check_securetty_context OUTPUT[860]: selinuxenabled OUTPUT[861]: selinuxexeccon OUTPUT[862]: sepdebugcrcfix OUTPUT[863]: sepol_check_access OUTPUT[864]: sepol_compute_av OUTPUT[865]: sepol_compute_member OUTPUT[866]: sepol_compute_relabel OUTPUT[867]: sepol_validate_transition OUTPUT[868]: seq


System information:
  • OS: Fedora 38
  • Language: C
  • IDE: Gnome Builder
  • sh: GNU bash, version 5.2.15 release (x86_64-redhat-linux-gnu)
Hi there,
First, a bit of a warning regarding this: Not saying you're trying to do anything malicious, but please be mindful of the security risks your question implies with "execute arbitrary code". Second, what are the binaries that your program does not have visibility to?
 
Hi there,
First, a bit of a warning regarding this: Not saying you're trying to do anything malicious, but please be mindful of the security risks your question implies with "execute arbitrary code". Second, what are the binaries that your program does not have visibility to?
Thanks for the comment!

Here's an analysis: https://docs.google.com/spreadsheets/d/1prqntLwx6kWG2ieg_yhpMHuU8fImDW9a9QeooODLcZo/edit#gid=0

Column D is the output of ls in /usr/bin/ from sh launched by C (1151 files), G is from the regular terminal (2702 files). I don't detect any pattern currently, though many of the commands that C can't find are user-installed (e.g. google-chrome) but some aren't (e.g. alias). More confusingly, shell launched from C picks up some files that the terminal doesn't. This is strange, as Builder doesn't claim to be using VM, meanwhile I can navigate to my home directory in sh launched from C and everything is there.
 
Thanks for the comment!

Here's an analysis: Commands

Column D is the output of ls in /usr/bin/ from sh launched by C (1151 files), G is from the regular terminal (2702 files). I don't detect any pattern currently, though many of the commands that C can't find are user-installed (e.g. google-chrome) but some aren't (e.g. alias). More confusingly, shell launched from C picks up some files that the terminal doesn't. This is strange, as Builder doesn't claim to be using VM, meanwhile I can navigate to my home directory in sh launched from C and everything is there.
Have you tried running your script under root?
 
Well technically a file is a linked list starting from a address in memory(hard disk).The root directory is at a specific address so you iterate over the linked list to get what you want.I dont know if the OS would give you access though.
 

New Threads

Buy us a coffee!

300x250
Top Bottom