Running Linux Mint I created a 2nd user to have 2 discord windows. After a quick single line fix in a config file, it works fine running 2 windows starting each from their respective user.
The other day while experimenting I found that I could run the 2nd discord instance from the same user as the first with this: su discord -c exit && discord (my 2nd user is named discord)
At first I thought it might be due to environment variables, but now Im not so sure. Based on the command prompt output it is using the 1st user’s .config. It must be getting something from the 2nd user because it will only work once, then it acts the same way as if I was launching discord twice from the first user.
What is happening in this command? How can I replicate it in a script?
(reading through this I just realized that && discord is being executed as part of the su -c, I had thought it was executing after. This partially explains the behaviour but I still dont understand why it is different from just executing: discord.)
Ok so I decided to read the man su page. - is used to load the environment, it doesnt make any difference in this case though, so it looks like its not environment variables.
su -c exit - discord && discord
is also the same result, so I might have been wrong about the && being added to the -c.
What does su ACTUALLY do? Is it mostly just permissions, or is there a lot more to it?
Right, but what does that mean?
What are the actual differences between being logged in as user1 versus user2?
I know there are environment variables and permissions, but what else?
A shell is an interactive program that can used to launch new applications. How does starting and closing a new shell cause Discord to bind sockets using permissions from the (presumably) closed shell?
Im terrible at explaining things, doesnt help that my knowledge here is a bit scattered. Let me try to rephrase.
Both of the first 2 will open a 2nd discord window, if discord is already started su -c discord - user2 is not equal to su -c exit - user2 && discord or (as user1)discord
The first one works great for running a second instance of Discord and was what I originally set out to do. The second is something I stumbled upon and I cant understand its behaviour.
Its behaviour is that it starts discord as user1, but with certain characteristics of user2, which allows user1 to run 2 separate applications of discord, not usually possible.
Based on the output Ive seen it appears that Discord is binding certain sockets, which is why only 1 instance can run per user. But with that second command it uses the user2’s sockets.
My question is really about all parts of this command, what are the differences between user1 and user2’s shells, how does && work in bash, and why does the interaction between su and && lead to this behaviour.
most likely it is because discord has some kind of global cookie, of some kind on your file system, which it uses to log in when started.
but since you’re actually running the program as a different user, it uses the config files from the second users home folder, but but the global cookie to log in.
The second and third command should do exactly the same. With the second on, you are launching a shell as user2, and issue the command “exit”, which closes the shell. So this whole bit does basically nothing.
Thats what you would think. However thats not what I am seeing. It somehow mixes User1 and 2.
I fixed discord so It binds to a unique socket each time its run, so I can now have unlimited discord instances on a single user. Just thought this was an interesting thing and since Im studying CS I was curious about why this works like that.
I think you have the operator precedence wrong here, or you have a typo. The && gets interpreted by your shell, so this is equivalent to: { su discord -c exit; } && { discord; }
Yes, these do appear to be equivalent. The && should trigger the discord command when su closes with exit status 0. It behaves the same when manually closing the shell without -c.
It seems like this is not as much something to do with && or su as much as it is Discord and the way that sockets and configurations are handled.
The behaviour I was seeing was that running discord as User1 would not start a 2nd a discord window. Running discord as User2 would start a 2nd discord window (with user2’s config). Running the su -c exit - discord && discord though as User1 would start a 2nd discord window (with user1’s config).
Sockets come in because I modified how discord names it sockets to allow running multiple windows. With the changes I made to the socket naming combined with the su && command lead to an unexpected outcome.