Index: trunk/src/VBox/Installer/solaris/Makefile.kmk
===================================================================
--- trunk/src/VBox/Installer/solaris/Makefile.kmk	(revision 42489)
+++ trunk/src/VBox/Installer/solaris/Makefile.kmk	(revision 42491)
@@ -159,4 +159,5 @@
 	$(VBOX_PATH_SOL_INST_SRC)/pkginstall.sh \
 	$(VBOX_PATH_SOL_INST_SRC)/smf-vboxballoonctrl.sh \
+	$(VBOX_PATH_SOL_INST_SRC)/smf-vboxautostart.sh \
 	$(if $(VBOX_WITH_WEBSERVICES),$(VBOX_PATH_SOL_INST_SRC)/smf-vboxwebsrv.sh,)
 
@@ -307,4 +308,5 @@
 	$(if $(VBOX_WITH_PYTHON),vboxshell.py,) \
 	smf-vboxballoonctrl.sh \
+	smf-vboxautostart.sh \
 	$(if $(VBOX_WITH_WEBSERVICES),smf-vboxwebsrv.sh,)
 
@@ -398,4 +400,5 @@
 	$(if $(VBOX_WITH_HEADLESS),VBoxHeadless) \
 	VBoxBalloonCtrl \
+	VBoxAutostart \
 	$(if $(VBOX_WITH_WEBSERVICES),vboxwebsrv) \
 	$(if $(VBOX_WITH_WEBSERVICES),webtest)
@@ -624,4 +627,5 @@
 	$(QUIET)$(if $(VBOX_WITH_WEBSERVICES),$(INSTALL) -m 0644 $(VBOX_PATH_SOL_INST_SRC)/virtualbox-webservice.xml         $(SOLARIS_VBOXSMF_DIR)/virtualbox-webservice.xml,)
 	$(QUIET)$(INSTALL) -m 0644 $(VBOX_PATH_SOL_INST_SRC)/virtualbox-balloonctrl.xml                                      $(SOLARIS_VBOXSMF_DIR)/virtualbox-balloonctrl.xml
+	$(QUIET)$(INSTALL) -m 0644 $(VBOX_PATH_SOL_INST_SRC)/virtualbox-autostart.xml                                        $(SOLARIS_VBOXSMF_DIR)/virtualbox-autostart.xml
 	$(QUIET)$(if $(not $(VBOX_WITH_NETFLT))$(INSTALL) -m 0755 $(PATH_ROOT)/src/VBox/Devices/Network/solaris/vnicinit_solaris.sh            $(SOLARIS_VBOXINST_DIR)/vnic_setup.sh,)
 	$(QUIET)$(if $(not $(VBOX_WITH_NETFLT))$(INSTALL) -m 0755 $(PATH_ROOT)/src/VBox/Devices/Network/solaris/vnicterm_solaris.sh            $(SOLARIS_VBOXINST_DIR)/vnic_term.sh,)
Index: trunk/src/VBox/Installer/solaris/VBox.sh
===================================================================
--- trunk/src/VBox/Installer/solaris/VBox.sh	(revision 42489)
+++ trunk/src/VBox/Installer/solaris/VBox.sh	(revision 42491)
@@ -38,4 +38,7 @@
         exec "$INSTALL_DIR/VBoxBalloonCtrl" "$@"
         ;;
+    VBoxAutostart|vboxautostart)
+        exec "$INSTALL_DIR/VBoxAutostart" "$@"
+        ;;
     vboxwebsrv)
         exec "$INSTALL_DIR/vboxwebsrv" "$@"
Index: trunk/src/VBox/Installer/solaris/checkinstall.sh
===================================================================
--- trunk/src/VBox/Installer/solaris/checkinstall.sh	(revision 42489)
+++ trunk/src/VBox/Installer/solaris/checkinstall.sh	(revision 42491)
@@ -141,4 +141,12 @@
 fi
 
+# Check if the autostart service is running, if so stop & remove it
+servicefound=`svcs -H "svc:/application/virtualbox/autostart" 2> /dev/null | grep '^online'`
+if test ! -z "$servicefound"; then
+    infoprint "VirtualBox autostart service appears to still be running."
+    infoprint "Halting & removing autostart service..."
+    /usr/sbin/svcadm disable -s svc:/application/virtualbox/autostart
+fi
+
 # Check if VBoxSVC is currently running
 VBOXSVC_PID=`ps -eo pid,fname | grep VBoxSVC | grep -v grep | awk '{ print $1 }'`
Index: trunk/src/VBox/Installer/solaris/makepackage.sh
===================================================================
--- trunk/src/VBox/Installer/solaris/makepackage.sh	(revision 42489)
+++ trunk/src/VBox/Installer/solaris/makepackage.sh	(revision 42491)
@@ -114,4 +114,5 @@
 ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxSDL
 ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxBalloonCtrl
+ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxAutostart
 ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/vboxwebsrv
 ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/webtest
Index: trunk/src/VBox/Installer/solaris/smf-vboxautostart.sh
===================================================================
--- trunk/src/VBox/Installer/solaris/smf-vboxautostart.sh	(revision 42491)
+++ trunk/src/VBox/Installer/solaris/smf-vboxautostart.sh	(revision 42491)
@@ -0,0 +1,75 @@
+#!/sbin/sh
+# $Id$
+
+# Copyright (C) 2012 Oracle Corporation
+#
+# This file is part of VirtualBox Open Source Edition (OSE), as
+# available from http://www.virtualbox.org. This file is free software;
+# you can redistribute it and/or modify it under the terms of the GNU
+# General Public License (GPL) as published by the Free Software
+# Foundation, in version 2 as it comes in the "COPYING" file of the
+# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+#
+
+#
+# smf-vboxautostart method
+#
+# Argument is the method name (start, stop, ...)
+
+. /lib/svc/share/smf_include.sh
+
+VW_OPT="$1"
+VW_EXIT=0
+
+case $VW_OPT in
+    start)
+        if [ ! -x /opt/VirtualBox/VBoxAutostart ]; then
+            echo "ERROR: /opt/VirtualBox/VBoxAutostart does not exist."
+            return $SMF_EXIT_ERR_CONFIG
+        fi
+
+        if [ ! -f /opt/VirtualBox/VBoxAutostart ]; then
+            echo "ERROR: /opt/VirtualBox/VBoxAutostart does not exist."
+            return $SMF_EXIT_ERR_CONFIG
+        fi
+
+        # Get svc configuration
+        VW_CONFIG=`/usr/bin/svcprop -p config/config $SMF_FMRI 2>/dev/null`
+        [ $? != 0 ] && VW_CONFIG=
+        VW_ROTATE=`/usr/bin/svcprop -p config/logrotate $SMF_FMRI 2>/dev/null`
+        [ $? != 0 ] && VW_ROTATE=
+        VW_LOGSIZE=`/usr/bin/svcprop -p config/logsize $SMF_FMRI 2>/dev/null`
+        [ $? != 0 ] && VW_LOGSIZE=
+        VW_LOGINTERVAL=`/usr/bin/svcprop -p config/loginterval $SMF_FMRI 2>/dev/null`
+        [ $? != 0 ] && VW_LOGINTERVAL=
+
+        # Provide sensible defaults
+        [ -z "$VW_CONFIG" ] && VW_CONFIG=/etc/vbox/autostart.cfg
+        [ -z "$VW_ROTATE" ] && VW_ROTATE=10
+        [ -z "$VW_LOGSIZE" ] && VW_LOGSIZE=104857600
+        [ -z "$VW_LOGINTERVAL" ] && VW_LOGINTERVAL=86400
+
+        # Get all users
+        for VW_USER in `logins -g staff`
+        do
+            exec su - "$VW_USER" -c "/opt/VirtualBox/VBoxAutostart --background --start --config \"$VW_CONFIG\" --logrotate \"$VW_ROTATE\" --logsize \"$VW_LOGSIZE\" --loginterval \"$VW_LOGINTERVAL\""
+
+            VW_EXIT=$?
+            if [ $VW_EXIT != 0 ]; then
+                echo "VBoxAutostart failed with $VW_EXIT."
+                VW_EXIT=1
+                break
+            fi
+        done
+    ;;
+    stop)
+        # Kill service contract
+        smf_kill_contract $2 TERM 1
+    ;;
+    *)
+        VW_EXIT=$SMF_EXIT_ERR_CONFIG
+    ;;
+esac
+
+exit $VW_EXIT
Index: trunk/src/VBox/Installer/solaris/vboxconfig.sh
===================================================================
--- trunk/src/VBox/Installer/solaris/vboxconfig.sh	(revision 42489)
+++ trunk/src/VBox/Installer/solaris/vboxconfig.sh	(revision 42491)
@@ -852,4 +852,5 @@
     stop_service "Web service" "virtualbox/webservice" "svc:/application/virtualbox/webservice:default"
     stop_service "Balloon control service" "virtualbox/balloonctrl" "svc:/application/virtualbox/balloonctrl:default"
+    stop_service "Autostart service" "virtualbox/autostart" "svc:/application/virtualbox/autostart:default"
     stop_service "Zone access service" "virtualbox/zoneaccess" "svc:/application/virtualbox/zoneaccess:default"
 
@@ -992,5 +993,6 @@
         if     test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-webservice.xml" \
             || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml" \
-            || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-balloonctrl.xml"; then
+            || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-balloonctrl.xml"\
+            || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-autostart.xml"; then
             infoprint "Configuring services..."
             if test "$REMOTEINST" -eq 1; then
Index: trunk/src/VBox/Installer/solaris/virtualbox-autostart.xml
===================================================================
--- trunk/src/VBox/Installer/solaris/virtualbox-autostart.xml	(revision 42491)
+++ trunk/src/VBox/Installer/solaris/virtualbox-autostart.xml	(revision 42491)
@@ -0,0 +1,103 @@
+<?xml version="1.0"?>
+<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
+<!--
+# Solaris SMF service manifest for VirtualBox autostart service.
+# $Id$
+
+     Copyright (C) 2012 Oracle Corporation
+
+     This file is part of VirtualBox Open Source Edition (OSE), as
+     available from http://www.virtualbox.org. This file is free software;
+     you can redistribute it and/or modify it under the terms of the GNU
+     General Public License (GPL) as published by the Free Software
+     Foundation, in version 2 as it comes in the "COPYING" file of the
+     VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+     hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+-->
+
+<service_bundle type='manifest' name='SUNWvbox:autostart'>
+
+<service
+    name='application/virtualbox/autostart'
+    type='service'
+    version='1'>
+
+    <single_instance />
+
+    <dependency
+        name='fs-local'
+        grouping='require_all'
+        restart_on='none'
+        type='service'>
+            <service_fmri value='svc:/system/filesystem/local' />
+    </dependency>
+
+    <dependency
+        name='network-service'
+        grouping='require_all'
+        restart_on='none'
+        type='service'>
+            <service_fmri value='svc:/network/service' />
+    </dependency>
+
+    <dependency
+        name='name-services'
+        grouping='require_all'
+        restart_on='refresh'
+        type='service'>
+            <service_fmri value='svc:/milestone/name-services' />
+    </dependency>
+
+    <instance name='default' enabled='false'>
+
+        <dependent
+            name='virtualbox-autostart_multi-user'
+            grouping='optional_all'
+            restart_on='none'>
+                <service_fmri value='svc:/milestone/multi-user' />
+        </dependent>
+
+        <exec_method
+            type='method'
+            name='start'
+            exec='/opt/VirtualBox/smf-vboxautostart.sh %m'
+            timeout_seconds='15'>
+            <method_context>
+                <method_credential user='root' group='root' />
+            </method_context>
+        </exec_method>
+
+        <exec_method
+            type='method'
+            name='stop'
+            exec=':kill'
+            timeout_seconds='15'>
+            <method_context>
+                <method_credential user='root' group='root' />
+            </method_context>
+        </exec_method>
+
+        <property_group name='startd' type='framework'>
+            <!-- sub-process core dumps/signals shouldn't restart session -->
+            <propval name='ignore_error' type='astring' value='core,signal' />
+        </property_group>
+
+        <property_group name='config' type='application'>
+            <propval name='config' type='astring' value='/etc/vbox/autostart.cfg' />
+        </property_group>
+
+        <template>
+            <common_name>
+                <loctext xml:lang='C'>
+                    VirtualBox Autostart
+                </loctext>
+            </common_name>
+        </template>
+
+    </instance>
+
+    <stability value='External' />
+
+</service>
+
+</service_bundle>
Index: trunk/src/VBox/Main/src-server/generic/AutostartDb-generic.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/generic/AutostartDb-generic.cpp	(revision 42489)
+++ trunk/src/VBox/Main/src-server/generic/AutostartDb-generic.cpp	(revision 42491)
@@ -190,4 +190,44 @@
     rc = autostartModifyDb(true /* fAutostart */, true /* fAddVM */);
     RTCritSectLeave(&this->CritSect);
+#elif defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+    NOREF(pszVMId); /* Not needed */
+    rc = VINF_SUCCESS;
+#else
+    NOREF(pszVMId);
+    rc = VERR_NOT_SUPPORTED;
+#endif
+
+    return rc;
+}
+
+int AutostartDb::removeAutostartVM(const char *pszVMId)
+{
+    int rc = VINF_SUCCESS;
+
+#if defined(RT_OS_LINUX)
+    NOREF(pszVMId); /* Not needed */
+    RTCritSectEnter(&this->CritSect);
+    rc = autostartModifyDb(true /* fAutostart */, false /* fAddVM */);
+    RTCritSectLeave(&this->CritSect);
+#elif defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+    NOREF(pszVMId); /* Not needed */
+    rc = VINF_SUCCESS;
+#else
+    NOREF(pszVMId);
+    rc = VERR_NOT_SUPPORTED;
+#endif
+
+    return rc;
+}
+
+int AutostartDb::addAutostopVM(const char *pszVMId)
+{
+    int rc = VINF_SUCCESS;
+
+#if defined(RT_OS_LINUX)
+    NOREF(pszVMId); /* Not needed */
+    RTCritSectEnter(&this->CritSect);
+    rc = autostartModifyDb(false /* fAutostart */, true /* fAddVM */);
+    RTCritSectLeave(&this->CritSect);
 #elif defined(RT_OS_DARWIN)
     NOREF(pszVMId); /* Not needed */
@@ -201,12 +241,12 @@
 }
 
-int AutostartDb::removeAutostartVM(const char *pszVMId)
-{
-    int rc = VINF_SUCCESS;
-
-#if defined(RT_OS_LINUX)
-    NOREF(pszVMId); /* Not needed */
-    RTCritSectEnter(&this->CritSect);
-    rc = autostartModifyDb(true /* fAutostart */, false /* fAddVM */);
+int AutostartDb::removeAutostopVM(const char *pszVMId)
+{
+    int rc = VINF_SUCCESS;
+
+#if defined(RT_OS_LINUX)
+    NOREF(pszVMId); /* Not needed */
+    RTCritSectEnter(&this->CritSect);
+    rc = autostartModifyDb(false /* fAutostart */, false /* fAddVM */);
     RTCritSectLeave(&this->CritSect);
 #elif defined(RT_OS_DARWIN)
@@ -221,42 +261,2 @@
 }
 
-int AutostartDb::addAutostopVM(const char *pszVMId)
-{
-    int rc = VINF_SUCCESS;
-
-#if defined(RT_OS_LINUX)
-    NOREF(pszVMId); /* Not needed */
-    RTCritSectEnter(&this->CritSect);
-    rc = autostartModifyDb(false /* fAutostart */, true /* fAddVM */);
-    RTCritSectLeave(&this->CritSect);
-#elif defined(RT_OS_DARWIN)
-    NOREF(pszVMId); /* Not needed */
-    rc = VINF_SUCCESS;
-#else
-    NOREF(pszVMId);
-    rc = VERR_NOT_SUPPORTED;
-#endif
-
-    return rc;
-}
-
-int AutostartDb::removeAutostopVM(const char *pszVMId)
-{
-    int rc = VINF_SUCCESS;
-
-#if defined(RT_OS_LINUX)
-    NOREF(pszVMId); /* Not needed */
-    RTCritSectEnter(&this->CritSect);
-    rc = autostartModifyDb(false /* fAutostart */, false /* fAddVM */);
-    RTCritSectLeave(&this->CritSect);
-#elif defined(RT_OS_DARWIN)
-    NOREF(pszVMId); /* Not needed */
-    rc = VINF_SUCCESS;
-#else
-    NOREF(pszVMId);
-    rc = VERR_NOT_SUPPORTED;
-#endif
-
-    return rc;
-}
-
