Tag Archives: opensolaris

Getting untruncated command line options passed to a Solaris process

If you have ever wanted to get the command line options that were passed to a running Solaris process, you might have noticed that the output of command line arguments from ps is truncated to 80 characters. Looking into /usr/include/sys/procfs.h will reveal the reason why! This is because of the restriction in struct psinfo. Here are the relevant fields from the definition of struct psinfo.

#define	PRFNSZ		16	/* Maximum size of execed filename */
#define	PRARGSZ		80	/* number of chars of arguments */
 
typedef struct psinfo {
         /* Fields omitted */
         char pr_fname[PRFNSZ];    /* name of exec'ed file */
         char pr_psargs[PRARGSZ];  /* initial characters of arg list */
         /* Fields omitted */
} psinfo_t;

So, due to the 80 characters restriction in psinfo::pr_psargs, the kernel will not be keeping track of arguments beyond the limit. Now, the only way to get the information is from the process’ memory of argv. In order to do this, you should have access to read the processes’ memory. This is the trick employed by both pargs and BSD version of ps with -ww switch.

To get the full length command line arguments passed to a process, you can do one of the following.

$ /usr/ucb/ps eww <pid>
$ pargs -l <pid>

One catch here is that, if the process has modified the argv since it was started, the output reported by both ps and pargs will show the modified data and not the initial arguments that were passed in. However, modifying argv within a program is not a standard practice and hence the chance of encountering such a scenario is remote.

Dumping core file from set-UID, set-GID ‘ed processes in Solaris

I had a previous post on how to turn on core files for set-UID, set-GID processes under Linux. Recently we ran into the same problem on Solaris. To turn on core files for set-id processes, use coreadm.

$ pfexec coreadm -e global-setid

Please keep in mind that these core files can have information that non-privileged user isn’t supposed to know. Quoting from Solaris man page:

     A process that is or ever has been setuid  or  setgid  since
     its  last  exec(2)  presents  security issues that relate to
     dumping  core.  Similarly,  a  process  that  initially  had
     superuser  privileges  and  lost  those  privileges  through
     setuid(2) also presents security issues that are related  to
     dumping core. A process of either type can contain sensitive
     information in  its  address  space  to  which  the  current
     nonprivileged  owner  of the process should not have access.
     If setid core files are enabled, they are created  mode  600
     and owned by the superuser.

Chainloading OpenSolaris from GRUB 2

I have a triple boot system with OpenSolaris, Ubuntu 9.10 and Microsoft Windows XP. I upgraded my Ubuntu 9.10 GRUB to GRUB 2 today. GRUB2 automatically added an entry for Microsoft Windows XP. However, it didn’t detect the OpenSolaris that was installed. I had to manually configure OpenSolaris chainloading in GRUB 2. If you are in a similar situation, this will be helpful for you to configure your GRUB 2.

Find your OpenSolaris partition.

$ sudo fdisk -l
 
Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00099420
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1       12158    97659103+   7  HPFS/NTFS
/dev/sda2   *       12159       24314    97643070   bf  Solaris
/dev/sda3           24317       38913   117250402+   f  W95 Ext'd (LBA)
/dev/sda5           24317       38297   112302351   83  Linux
/dev/sda6           38298       38913     4947988+  82  Linux swap / Solaris

In my case, it is /dev/sda2. Once you have found it, edit /etc/grub.d/40_custom and add the following entry for OpenSolaris. A key difference between GRUB and GRUB 2 is the device numbering. In GRUB, sda2 is (hd0,1). However, in GRUB 2, sda2 is (hd0,2). Keep this in mind when you are configuring your GRUB 2.

# Chainload OpenSolaris GRUB.
menuentry "Chainload OpenSolaris GRUB" {
    set root=(hd0,2)
    chainloader +1
}

Now your /etc/grub.d/40_custom should look like the following.

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
 
# Chainload OpenSolaris GRUB.
menuentry "Chainload OpenSolaris GRUB" {
    set root=(hd0,2)
    chainloader +1
}

Then run update-grub to regenerate /boot/grub/grub.cfg.

$ sudo update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.31-19-generic
Found initrd image: /boot/initrd.img-2.6.31-19-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Microsoft Windows XP Professional on /dev/sda1
done

You will not find anything about OpenSolaris in the output message. However, you can examine /boot/grub/grub.cfg to find if an entry is added for OpenSolaris.

$ tail -10 /boot/grub/grub.cfg 
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
 
# Chainload OpenSolaris GRUB.
menuentry "Chainload OpenSolaris GRUB" {
    set root=(hd0,2)
    chainloader +1
}
### END /etc/grub.d/40_custom ###

Enabling virtual consoles in OpenSolaris

OpenSolaris was lacking virtual console for a while. This support was made available since build snv_124. However, due to various bugs, it is turned off by default. To enable virtual consoles, do the following.

$ pfexec svcadm enable vtdaemon
$ pfexec svcadm enable console-login:vt2
$ pfexec svcadm enable console-login:vt3
$ pfexec svcadm enable console-login:vt4
$ pfexec svcadm enable console-login:vt5
$ pfexec svcadm enable console-login:vt6

To enable hot keys for switching virtual consoles, do the following.

$ pfexec svccfg -s vtdaemon setprop options/hotkeys=true
$ pfexec svcadm refresh vtdaemon
$ pfexec svcadm restart vtdaemon

Console security is enabled by default. What it means is that if you leave a virtual console and move to another one, the previous virtual console will be locked and you will have to provide the password to unlock it. If you don’t like that, turn the security off.

$ pfexec svccfg -s vtdaemon setprop options/secure=false
$ pfexec svcadm refresh vtdaemon
$ pfexec svcadm restart vtdaemon

If you have already logged into an X session while doing this, logout and wait for Xorg to restart. After that, you should be able to switch between the virtual consoles by pressing the hotkey Alt + Ctrl + F#, where # => 1 to 7. Console 1 is the primary console, 2-6 are virtual consoles and 7 is the Xorg.

Random links for week 45

  • I have an Apple TV and I run XBMC and Boxee on my Apple TV using Patchstick. Apple introduced Apple TV 3.0 Software last week. Somehow, the software just got upgraded automatically causing me to lose XBMC and Boxee. Patchstick isn’t available for Apple TV 3.0 yet. So, I had to downgrade it using another Patchstick product (Canadian based).
  • I am using Whey protein supplement as my post workout drink for a while now. Recently, I came across Casein protein supplements and started using it too. I take Whey after workout and take Casein before going to bed (only on workout days). Here is an article that compares Whey and Casein.
  • I am using magit mode in Emacs with my git repositories. It is quite helpful most of the times.
  • DTrace is a powerful tool for tracing a process. Recently, we have started working on defining Statically Defined Tracing for our system. I feel that it is a quite powerful way to approach system tracing.

Random links for week 44

  • Since I updated to OpenSolaris update snv_124, I am facing issues with Indic fonts rendering. I have created a bug describing the problem. The root cause of the problem isn’t diagonized yet. If someone knows what could be wrong, please let me know.
  • I keep hearing a lot about Haskell lately and wanted to get introduced to functional programming through Haskell. David Carlton and friends recently started a Haskell study group. It was a great opportunity and wonderful setting for learning Haskell! I just joined the group. We are studying Real World Haskell. The book is available online. I am currently on chapter 3 and it is engaging. Please feel free to join the mailing list, if interested.
  • My latest Emacs addiction is Org-Mode. I started using Org-Mode to maintain my GTD workflow. I am also using it as my note taking tool and daily/weekly status reporting tool at work. Org-Mode is very powerful! Give it a try and you will find out.
  • I just got back into the habit of going to gym regularly after a couple of busy months at work. This time, one of my primary goal is to able to do unassisted chin-ups. Here is an article on how to increase one’s chin-ups. Currently, I am focusing on negatives.
  • I am a big fan of Hyderabadi Chicken Biryani. I came across this great recipe on YouTube and tried it out a couple of times. The one I prepared yesterday turned out really great! If you are a Biryani fan, I would strongly recommend this recipe.

Fix mouse cursor jumping to top left corner of screen on OpenSolaris

Update 2009-11-07: This issue is fixed in OpenSolaris build snv_126.

OpenSolaris dev repository update snv_116 introduced an XOrg bug that caused the mouse cursor to jump to the top left corner of the screen very frequently. Apparently, there is some floating point math issue is involved using MMX/SSE2 instructions. I was living with the workaround posted on bugzilla. I was hoping that the bug would soon be fixed in the subsequent updates. Yesterday, I updated to build snv_122 and found that the issue still exists. Hence, I am posting about the workaround to fix this issue.

$ pfexec bash
# cp -p /usr/X11/bin/i386/Xorg /usr/X11/bin/i386/Xorg.orig 
# echo 'xf86SigioReadInput+9?w 770f 9090 9090' | mdb -w /usr/X11/bin/i386/Xorg

This bug is currently tracked in bugster.

Random links for week 36

  • My (ex-)manager David Carlton has decided to leave us to join Playdom. I learned a lot in the past two years working with him. We are going to miss him a lot! Playdom is fortunate to have such a talented individual on board. I am sure he will be bringing a multitude of perspectives into the game development at Playdom. I wish him all the very best in his new exciting game development career.
  • I am using git as my primary version control system at work. Lately, more of my friends have shown interest towards using git. For them, I would recommend knowing why git is better than other version control systems.
  • Recently, I have started editing multiple files with the same name (under different directories) simultaneously on my GNU Emacs more often. This got me confused easily and made me prone to making mistakes by editing wrong files. Here is a cool way to make buffer names unique in GNU Emacs.
  • Due to certain changes that are happening recently in our team, being agile is more of a necessity that ever before. I am seriously thinking of attending Agile Open California. Agile Open California is a coalition of agile practitioners and advocates with an intention to provide an opportunity for learning, networking and growth to the Agile community in California and others who are interested.
  • We are currently working on transitioning our software to 64-bit on Solaris. We run into interesting problems each day. Solaris 64-bit developer’s guide is a source of must know information for anyone who is working on developing 64-bit applications on Unix like platforms, especially Solaris.
  • Since I returned from India after my recent vacation, I haven’t got much chance to workout in the gym. I would like to use this opportunity for refreshing my appreciation of the basics of weight training and get a fresh start as early as next week.

GNOME Metacity dual screen issue in OpenSolaris 2009.06

With the latest OpenSolaris 2009.06, maximizing windows managed by Metacity (GNOME) will maximize the windows across both screens. This is due to an issue that Metacity was trying to use a wrong Xinerama type. This issue is fixed in the mercurial repository. However, the fix was not on time to make it into the final release of OpenSolaris 2009.06. But, there is a quick workaround for this issue. Here is the set of instructions.

Step 1. Backup your current metacity.

$ pfexec cp /usr/bin/metacity /usr/bin/metacity.orig

Step 2. Download the fixed Metacity binary from developer’s site and replace the original binary.

$ wget http://www.gnome.org/~erwannc/bugs/8748/metacity -O /tmp/metacity
$ pfexec cp /tmp/metacity /usr/bin/metacity

Note: Don’t do this in one step using wget -O /usr/bin/metacity. This broke my system.

Step 3. (Optional) By now, your new Metacity should have already started working. If not, replace the current instance by hand.

$ metacity --replace

Happy dual-screening on your OpenSolaris 2009.06!

Creating OpenSolaris live USB sticks

OpenSolaris 2009.06 was announced yesterday. You can download the live CD image (ISO) from here. Here is the set of instructions to create a live USB stick from the live CD that you have downloaded.

Step 1. Install distro-construct.

$ pfexec pkg install SUNWdistro-const

Step 2. Generate the USB image from CD image.

$ pfexec usbgen osol-0906-x86.iso osol-0906-x86-usb.img /tmp/osol

Step 3. Copy the generated USB image on to the USB stick.

$ pfexec usbcopy osol-0906-x86-usb.img

On executing the above command, you will be shown the list of removable media and asked to select the one to use with usbcopy. If you have inserted only one USB media, you will see only one entry to choose from. Please note that you may have to unmount the USB media from your GNOME file manager or command line, before usbcopy starts.

Once usbcopy completes, your OpenSolaris live USB sticks are ready to boot a live environment and perform installation. I will be in Community One West, Deep Dive sessions today (Jun 2, 2009) at Intercontinental Hotel, San Francisco. If anyone needs to make their USB media an OpenSolaris live media, please contact me.