bash: cannot set terminal process group (-1): Inappropriate ioctl for device

130
  • su - username runs the login shell of username as an interactive shell.

  • su username command arguments runs command arguments non-interactively under the account username.

You command su lfs - -c "source ~/.bash_profile" means run - -c "source ~/.bash_profile" as the user lfs non-interactively. Now the shell sees the option - and says, I am to run as an interative login shell, and tries to initialize the terminal, but su has disconnected the child process from the controlling terminal.

In short: The - is either misplaced or erroneous.

For a longer discussion, see practically the the same question on serverfault.

Share:
130

Related videos on Youtube

John S.
Author by

John S.

Updated on September 18, 2022

Comments

  • John S.
    John S. almost 2 years

    I'm trying to do this:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    
    #define MAX_SIZE 50
    int main()
    {
        char *s = malloc(sizeof(char)*MAX_SIZE);
        do{
          int r = read(STDIN_FILENO, s, MAX_SIZE);
          if(r==-1) printf("error ");
    
          else{
            write(STDERR_FILENO, s, MAX_SIZE);
          }
    
          while(getchar()!='\n');
        } while(strcmp(s,"end\n")!=0);
    
        free(s);
        return 0;
    }
    

    My question is: is fflush(stdin) in this case an undefined behavior? As I searched on internet, I readed that in a case fflush(stdin) is a defined behavior: By the standard C pass an input stream to fflush is an undefined behavior ... STDIN is an input stream (buffered) I think the undefined behavior is when the standard C doesn't specify which behavior must have a specific function in specific cases.

    So it is an undefined behavior by following the standard C right?

    So is in this case an undefined behavior?

    • Ed Heal
      Ed Heal almost 9 years
      Not a good idea to mix stdio library and using raw file descriptors.
    • Jonathan Wakely
      Jonathan Wakely almost 9 years
      This question is very unclear. You've shown some code which doesn't use fflush and is full of irrelevant distractions, the malloc and free are useless (just use char s[50]), MAX_SIZE is useless, sizeof(char) is useless etc. Also the "question" is the same thing repeated 3 or 4 times with slightly different phrasing and poor punctuation, then you ask the same question twice more. Couldn't the whole thing be simply "is fflush(stdin) undefined behaviour?" and get rid of all the rest?!
    • John S.
      John S. almost 9 years
      Why a bad idea? @Ed Heal
    • Ed Heal
      Ed Heal almost 9 years
      Because stdio uses a buffer, raw pointers does not. Things get confusing.
    • John S.
      John S. almost 9 years
      Ok ... Now I understood ... But why 'sizeof(char)' are useless? No-sense ... They let you read easily the source and is portability
    • Bo Persson
      Bo Persson almost 9 years
      @JohnS. - sizeof(char) is defined to always be 1, even on odd systems where char is larger than 8 bits.
    • John S.
      John S. almost 9 years
      Then it's useless? And why?
    • Ed Heal
      Ed Heal almost 9 years
      Sizeof(char) is defined as one. - code using if seems cluttered
    • John S.
      John S. almost 9 years
      Yes, this is true, but linux disposes function to get a descriptor file from a file pointer. It's good to use them.
    • John S.
      John S. almost 9 years
      (functions like fileno() )
    • Mark Plotnick
      Mark Plotnick over 7 years
      Do you want su to run bash as if it were a login shell? If so, then try su - lfs -c ... or su --login lfs -c ... or su lfs --login -c ....
    • sprocket12
      sprocket12 over 7 years
      @MarkPlotnick That gives the same error.
  • dhke
    dhke almost 9 years
    SingleUnix adds behavior for seekable input streams. I'm not so sure if this is actually useful and implemented anywhere, though.
  • John S.
    John S. almost 9 years
    Thank you very much! Now I understood. Thanks.
  • Jonathan Wakely
    Jonathan Wakely almost 9 years
    @dhke, that's a good point, POSIX (which is implemented very widely!) makes it defined as an extension to the base C standard. But it only has an effect for streams capable of seeking, which stdin typically isn't.
  • dhke
    dhke almost 9 years
    That implemented anywhere was meant to specifically refer to this particular feature. Because e.g. on Linux and FreeBSD fflush() the man page documents behavior as to simply signal EBADF for input streams. Solaris documents POSIX behavior, though.
  • Jonathan Wakely
    Jonathan Wakely almost 9 years
    Because sizeof(char) is always 1 on all systems everywhere, you can just write 1. It's simpler. Your example could have just used char s[MAX_SIZE]; and not needed malloc, free or sizeof(char) at all.
  • AlexP
    AlexP over 7 years
    Summary: the correct syntax is either su username command arguments, su username, or su - username. The form used by the original poster, su username - command arguments is incorrect.
  • sprocket12
    sprocket12 over 7 years
    @AlexP Thanks for your reply. Why do you think the previous lines in the script work? They use the same syntax.