bash: cannot set terminal process group (-1): Inappropriate ioctl for device
su - username
runs the login shell ofusername
as an interactive shell.su username command arguments
runscommand arguments
non-interactively under the accountusername
.
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.
Related videos on Youtube
John S.
Updated on September 18, 2022Comments
-
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 almost 9 yearsNot a good idea to mix stdio library and using raw file descriptors.
-
Jonathan Wakely almost 9 yearsThis question is very unclear. You've shown some code which doesn't use
fflush
and is full of irrelevant distractions, themalloc
andfree
are useless (just usechar 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 "isfflush(stdin)
undefined behaviour?" and get rid of all the rest?! -
John S. almost 9 yearsWhy a bad idea? @Ed Heal
-
Ed Heal almost 9 yearsBecause stdio uses a buffer, raw pointers does not. Things get confusing.
-
John S. almost 9 yearsOk ... Now I understood ... But why 'sizeof(char)' are useless? No-sense ... They let you read easily the source and is portability
-
Bo Persson almost 9 years@JohnS. -
sizeof(char)
is defined to always be 1, even on odd systems wherechar
is larger than 8 bits. -
John S. almost 9 yearsThen it's useless? And why?
-
Ed Heal almost 9 yearsSizeof(char) is defined as one. - code using if seems cluttered
-
John S. almost 9 yearsYes, this is true, but linux disposes function to get a descriptor file from a file pointer. It's good to use them.
-
John S. almost 9 years(functions like fileno() )
-
Mark Plotnick over 7 yearsDo you want
su
to run bash as if it were a login shell? If so, then trysu - lfs -c ...
orsu --login lfs -c ...
orsu lfs --login -c ...
. -
sprocket12 over 7 years@MarkPlotnick That gives the same error.
-
-
dhke almost 9 yearsSingleUnix adds behavior for seekable input streams. I'm not so sure if this is actually useful and implemented anywhere, though.
-
John S. almost 9 yearsThank you very much! Now I understood. Thanks.
-
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 almost 9 yearsThat 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 signalEBADF
for input streams. Solaris documents POSIX behavior, though. -
Jonathan Wakely almost 9 yearsBecause
sizeof(char)
is always 1 on all systems everywhere, you can just write 1. It's simpler. Your example could have just usedchar s[MAX_SIZE];
and not needed malloc, free or sizeof(char) at all. -
AlexP over 7 yearsSummary: the correct syntax is either
su username command arguments
,su username
, orsu - username
. The form used by the original poster,su username - command arguments
is incorrect. -
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.